Submission #879192

#TimeUsernameProblemLanguageResultExecution timeMemory
879192MilosMilutinovicPlus Minus (BOI17_plusminus)C++14
100 / 100
151 ms14340 KiB
#include <bits/stdc++.h> using namespace std; const int md = 1e9 + 7; int ckmul(int a, int b) { return a * 1LL * b % md; } int ckadd(int a, int b) { return a + b >= md ? a + b - md : a + b; } int powmod(int x, int k) { int res = 1; while (k) { if (k & 1) { res = ckmul(res, x); } x = ckmul(x, x); k >>= 1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<char> c(k); vector<int> x(k); vector<int> y(k); for (int i = 0; i < k; i++) { cin >> c[i] >> x[i] >> y[i]; } int ans = 0; { // row map<int, vector<int>> mp; for (int i = 0; i < k; i++) { mp[x[i]].push_back(i); } bool ok = true; for (auto& p : mp) { vector<vector<bool>> f(2, vector<bool>(2)); for (int i : p.second) { int p = (y[i] % 2); int v = (c[i] == '+' ? 0 : 1); f[p][v] = true; } if ((f[0][0] && f[0][1]) || (f[1][0] && f[1][1]) || (f[0][0] && f[1][0]) || (f[0][1] && f[1][1])) { ok = false; } } if (ok) { ans = ckadd(ans, powmod(2, n - (int) mp.size())); } } { // col map<int, vector<int>> mp; for (int i = 0; i < k; i++) { mp[y[i]].push_back(i); } bool ok = true; for (auto& p : mp) { vector<vector<bool>> f(2, vector<bool>(2, false)); for (int i : p.second) { int p = (x[i] % 2); int v = (c[i] == '+' ? 0 : 1); f[p][v] = true; } if ((f[0][0] && f[0][1]) || (f[1][0] && f[1][1]) || (f[0][0] && f[1][0]) || (f[0][1] && f[1][1])) { ok = false; } } if (ok) { ans = ckadd(ans, powmod(2, m - (int) mp.size())); } } { for (char ch : {'+', '-'}) { bool ok = true; for (int i = 0; i < k; i++) { char v = ((x[i] + y[i]) % 2 == 0 ? ch : (ch ^ '-' ^ '+')); if (v != c[i]) { ok = false; } } if (ok) { ans -= 1; if (ans < 0) { ans += md; } } } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...