Submission #823434

#TimeUsernameProblemLanguageResultExecution timeMemory
823434serifefedartarPlus Minus (BOI17_plusminus)C++17
100 / 100
114 ms11812 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define MOD 1000000007 #define LOGN 20 #define MAXN 2005 map<int,int> row_repet, col_repet; ll binExp(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res; } int main() { fast ll N, M, K; cin >> N >> M >> K; bool rowCheck = true, colCheck = true; for (int i = 0; i < K; i++) { char ch; int row, col; cin >> ch >> row >> col; int rowRepType, colRepType; if (ch == '+') { if (col % 2) rowRepType = 1; else rowRepType = 2; if (row % 2) colRepType = 1; else colRepType = 2; } else { if (col % 2) rowRepType = 2; else rowRepType = 1; if (row % 2) colRepType = 2; else colRepType = 1; } if (row_repet[row] != 0 && row_repet[row] != rowRepType) rowCheck = false; else row_repet[row] = rowRepType; if (col_repet[col] != 0 && col_repet[col] != colRepType) colCheck = false; else col_repet[col] = colRepType; } ll ans = 0; if (rowCheck) ans = (ans + binExp(2, N - row_repet.size())) % MOD; if (colCheck) ans = (ans + binExp(2, M - col_repet.size())) % MOD; if (rowCheck && colCheck) { bool firstCase = true, secondCase = true; for (auto u : row_repet) { if (u.f % 2 == u.s % 2) secondCase = false; else firstCase = false; } for (auto u : col_repet) { if (u.f % 2 == u.s % 2) secondCase = false; else firstCase = false; } ans = ans - firstCase - secondCase; } while (ans < 0) ans += MOD; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...