Submission #1080449

#TimeUsernameProblemLanguageResultExecution timeMemory
1080449andrei_iorgulescuPlus Minus (BOI17_plusminus)C++14
100 / 100
144 ms21332 KiB
#include <bits/stdc++.h> using namespace std; int modulo = 1e9 + 7; int n,m,k; int lgpow(int x, int y) { int z = 1; while (y != 0) { if (y % 2 == 1) z = 1ll * z * x % modulo; x = 1ll * x * x % modulo; y /= 2; } return z; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> k; bool nah1 = false, nah2 = false; set<int> ff1, ff2; map<int,int> lin, col; bool could_be_chessboard_1 = true, could_be_chessboard_2 = true; for (int i = 1; i <= k; i++) { char spin; int x,y; cin >> spin >> x >> y; ff1.insert(x); ff2.insert(y); if (spin == '+' and (x + y) % 2 == 0) could_be_chessboard_1 = false; if (spin == '+' and (x + y) % 2 == 1) could_be_chessboard_2 = false; if (spin == '-' and (x + y) % 2 == 0) could_be_chessboard_2 = false; if (spin == '-' and (x + y) % 2 == 1) could_be_chessboard_1 = false; if (spin == '+') { if (lin[x] != 0) { if (lin[x] != 1 + y % 2) { nah1 = true; } } else lin[x] = 1 + y % 2; } else { if (lin[x] != 0) { if (lin[x] != 1 + (y - 1) % 2) { nah1 = true; } } else lin[x] = 1 + (y - 1) % 2; } if (spin == '+') { if (col[y] != 0) { if (col[y] != 1 + x % 2) { nah2 = true; } } else col[y] = 1 + x % 2; } else { if (col[y] != 0) { if (col[y] != 1 + (x - 1) % 2) { nah2 = true; } } else col[y] = 1 + (x - 1) % 2; } } int ans = 0; if (!nah1) ans += lgpow(2, n - (int)ff1.size()); if (!nah2) ans += lgpow(2, m - (int)ff2.size()); if (could_be_chessboard_1) ans--; if (could_be_chessboard_2) ans--; cout << ans % modulo; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...