fork download
  1. #include <iostream>
  2. #include <bitset>
  3. #include <cassert>
  4. using namespace std;
  5.  
  6. int n, m;
  7. bool encode(int x, int y, int dir, int& res) {
  8. res = dir * 64 + x * m + y;
  9. return x >= 0 && x + dir < n && y >= 0 && y + !dir < m;
  10. }
  11. bool go(bitset<128> cur, int x, int y) {
  12. int res = 0;
  13. int move;
  14. if (!res && encode(x - 1, y, 1, move) && !cur[move]) cur[move] = 1, res |= !go(cur, x - 1, y), cur[move] = 0;
  15. if (!res && encode(x, y - 1, 0, move) && !cur[move]) cur[move] = 1, res |= !go(cur, x, y - 1), cur[move] = 0;
  16. if (!res && encode(x, y, 1, move) && !cur[move]) cur[move] = 1, res |= !go(cur, x + 1, y), cur[move] = 0;
  17. if (!res && encode(x, y, 0, move) && !cur[move]) cur[move] = 1, res |= !go(cur, x, y + 1), cur[move] = 0;
  18. return res;
  19. }
  20. int main() {
  21. cin >> n >> m;
  22. assert(n * m < 64);
  23. bitset<128> bs;
  24. cout << (go(bs, 0, 0) ? 'A' : 'B') << endl;
  25. return 0;
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
Success #stdin #stdout 0s 15232KB
stdin
3 14
stdout
A