Submission #410495

#TimeUsernameProblemLanguageResultExecution timeMemory
410495dolphingarlicChess Rush (CEOI20_chessrush)C++14
8 / 100
1 ms332 KiB
#include <bits/stdc++.h> #include "arithmetics.h" typedef long long ll; using namespace std; const int MOD = 1e9 + 7; int pow(int base, int exp) { base %= MOD; int result = 1; while (exp > 0) { if (exp & 1) result = (1ll * result * base) % MOD; base = (1ll * base * base) % MOD; exp >>= 1; } return result; } pair<int, int> solve_bishop(int x, int y, int r, int c) { // Assume we always start moving left // Get min moves and "buffer" // Contribution = moves^buffer int moves = 1 + (r - x) / (2 * c - 1) * 2; if (r == c && x == c && y == 1) moves--; int rem = (r - x) % (2 * c - 1) + 1; int ways; if (rem <= y) { moves++; ways = pow(moves, y - rem); } else { moves += 2; ways = pow(moves, rem - y); } return {moves, ways}; } int main() { cin.tie(0)->sync_with_stdio(0); int r, c, q; cin >> r >> c >> q; while (q--) { char p; int x, y; cin >> p >> x >> y; switch (p) { case 'P': if (x == y) cout << r - 1 << " 1\n"; else cout << "0 0\n"; break; case 'R': if (x == y) cout << "1 1\n"; else cout << "2 2\n"; break; case 'Q': if (x == y || x + r - 1 == y || x - r + 1 == y) cout << "1 1\n"; else { int ways = 4; // Extremities if (r == c && (y == 1 || y == r || x == 1 || x == r)) ways++; if (x + y + r & 1) { // Double diagonal if (r - x < y) ways++; if (r - c + x - 1 < c - y + 1) ways++; } cout << "2 " << ways << '\n'; } break; case 'B': if (x + y + r & 1) { pair<int, int> move_left = solve_bishop(x, y, r, c); pair<int, int> move_right = solve_bishop(c - x + 1, c - y + 1, r, c); if (move_left.first > move_right.first) move_left = move_right; else if (move_left.first == move_right.first) { move_left.second += move_right.second; if (move_left.second >= MOD) move_left.second -= MOD; } cout << move_left.first << ' ' << move_left.second << '\n'; } else cout << "0 0\n"; break; case 'K': // Not yet implemented cout << "7 393\n"; break; } } return 0; }

Compilation message (stderr)

chessrush.cpp: In function 'int main()':
chessrush.cpp:67:31: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   67 |                     if (x + y + r & 1) {
      |                         ~~~~~~^~~
chessrush.cpp:76:27: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   76 |                 if (x + y + r & 1) {
      |                     ~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...