AtCoder Beginner Contest 198 D
種別: 記事
カテゴリ: 競技プログラミング
サブカテゴリ: AtCoder > AtCoder Beginner Contest 198
タグ: #解いた問題
(工事中)
2021年4月11日にAtCoder で開催されたコンテストであるAtCoder Beginner Contest 198 のD問題に関するメモ
解き方
解答例
下は上記の方法で解いたときの提出結果である。また、その提出の際に提出したソースコードをその下に転記する。
code: C
#include <stdio.h>
#include <string.h>
int func(int i, int uniqCount, int *map, int *used, int *a, char *s1, char *s2, char *s3, long long *n) {
int j = 0;
int solved = 0;
if (i >= uniqCount) {
int k = 0;
if(map[a[s10-'a']-1] == 0) {
return -1;
}
if(map[a[s20-'a']-1] == 0) {
return -1;
}
if(map[a[s30-'a']-1] == 0) {
return -1;
}
while(s1k != '\0') {
n0 *= 10;
n0 += map[a[s1k-'a']-1];
k++;
}
k = 0;
while(s2k != '\0') {
n1 *= 10;
n1 += map[a[s2k-'a']-1];
k++;
}
k = 0;
while(s3k != '\0') {
n2 *= 10;
n2 += map[a[s3k-'a']-1];
k++;
}
if (n0 + n1 != n2) {
n0 = 0;
n1 = 0;
n2 = 0;
return -1;
}
return 0;
}
while(solved < 1 && j < 10) {
if (usedj < 1) {
usedj = 1;
mapi = j;
if(func(i+1, uniqCount, map, used, a, s1, s2, s3, n) >= 0) {
solved = 1;
}
usedj = 0;
}
j++;
}
if (solved > 0) {
return 0;
}
return -1;
}
int main () {
char s111 = "";
char s211 = "";
char s311 = "";
int a26 = {};
int uniqCount = 0;
int i = 0;
int used10 = {};
int map10 = {};
long long n3 = {};
int res = 0;
res = scanf("%s", s1);
res = scanf("%s", s2);
res = scanf("%s", s3);
while (s1i != '\0') {
if (a[s1i-'a'] == 0) {
uniqCount++;
a[s1i-'a'] = uniqCount;
}
i++;
}
i = 0;
while (s2i != '\0') {
if (a[s2i-'a'] == 0) {
uniqCount++;
a[s2i-'a'] = uniqCount;
}
i++;
}
i = 0;
while (s3i != '\0') {
if (a[s3i-'a'] == 0) {
uniqCount++;
a[s3i-'a'] = uniqCount;
}
i++;
}
i = 0;
if (uniqCount > 10) {
printf("UNSOLVABLE\n");
return 0;
}
if(func(0, uniqCount, map, used, a, s1, s2, s3, n) < 0) {
printf("UNSOLVABLE\n");
return 0;
}
printf("%lld\n", n0);
printf("%lld\n", n1);
printf("%lld\n", n2);
return 0;
}
私の提出一覧
table: submissions_atcoder_begginer_contest_198_D
提出のURL 提出時刻 結果 備考
1回目 https://atcoder.jp/contests/abc198/submissions/21690251 2021-04-11T22:38:11+0900 WA
2回目 https://atcoder.jp/contests/abc198/submissions/21691335 2021-04-11T22:39:56+0900 CE
3回目 https://atcoder.jp/contests/abc198/submissions/21691579 2021-04-11T22:40:29+0900 AC コンテスト終了直後に提出
感想