#include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) int res[9][9] = { {1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 0, -1, -1, -1, -1, -1, -1, -1}, {1, 1, 0, -1, -1, -1, -1, -1, -1}, {1, 6, 1, 0, -1, -1, -1, -1, -1}, {1, 22, 40, 1, 0, -1, -1, -1, -1}, {1, 65, 570, 387, 1, 0, -1, -1, -1}, {1, 171, 4970, 21837, 5788, 1, 0, -1, -1}, {1, 420, 33887, 576247, 1353096, 133500, 1, 0, -1}, {1, 988, 201152, 10151470, 110940707, 142458868, 4682269, 1, 0} }; int main() { int q; scanf("%d", &q); REP(qq,q) { int n, k; scanf("%d%d", &n, &k); if (!k) printf("1\n"); else if (n == k) printf("0\n"); else if (n == k + 1) printf("1\n"); else if (n < 9) printf("%d\n", res[n][k] & 1); else printf("%d\n", ~k & 1); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) int res[9][9] = { {1, -1, -1, -1, -1, -1, -1, -1, -1}, {1, 0, -1, -1, -1, -1, -1, -1, -1}, {1, 1, 0, -1, -1, -1, -1, -1, -1}, {1, 6, 1, 0, -1, -1, -1, -1, -1}, {1, 22, 40, 1, 0, -1, -1, -1, -1}, {1, 65, 570, 387, 1, 0, -1, -1, -1}, {1, 171, 4970, 21837, 5788, 1, 0, -1, -1}, {1, 420, 33887, 576247, 1353096, 133500, 1, 0, -1}, {1, 988, 201152, 10151470, 110940707, 142458868, 4682269, 1, 0} }; int main() { int q; scanf("%d", &q); REP(qq,q) { int n, k; scanf("%d%d", &n, &k); if (!k) printf("1\n"); else if (n == k) printf("0\n"); else if (n == k + 1) printf("1\n"); else if (n < 9) printf("%d\n", res[n][k] & 1); else printf("%d\n", ~k & 1); } } |