이항계수가 생각나는 문제다.
쌩으로 배열 만들어도 메모리가 부족하지 않을 것 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <string.h> using namespace std; int d[2][4004], c[] = { 3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1 }, len, r; char a[2002], b[2002]; int main() { scanf("%s %s", &a, &b); len = strlen(a); for (int i = 0; i < len; i++) { d[0][i*2] = c[a[i] - 'A']; d[0][i*2 + 1] = c[b[i] - 'A']; } len *= 2; r = len - 2; for (int i = 0; i < r; i++) for (int j = 0; j < len - i - 1; j++) d[(i + 1) % 2][j] = (d[i % 2][j] + d[i % 2][j + 1])%10; printf("%d%d", d[r % 2][0]%10, d[r % 2][1]%10); return 0; } | cs |
'BOJ' 카테고리의 다른 글
15270 친구 팰린드롬 (0) | 2018.02.17 |
---|---|
15271 친구 팰린드롬 2 (0) | 2018.02.17 |
1371 가장 많은 글자 (0) | 2018.02.17 |
14950 정복자 (0) | 2018.02.17 |
14949 외계 미생물 (0) | 2018.02.17 |