페이지

1074번: Z

https://www.acmicpc.net/problem/1074


#include<cstdio>
int n, r, c;
void f(int s, int x, int y, int t) {
    if (!s&&x == r&&y == c) {
        printf("%d\n", t);
        return;
    }
    if (r<x || c<y || x + 2 * s <= r || y + 2 * s <= c) return;
    f(s / 2, x, y, t);
    f(s / 2, x, y + s, t + s*s);
    f(s / 2, x + s, y, t + s*s * 2);
    f(s / 2, x + s, y + s, t + s*s * 3);
}
int main() {
    while (~scanf("%d%d%d", &n, &r, &c)) f(1 << n - 1, 0, 0, 0);
    return 0;
}

댓글 없음 :

댓글 쓰기