This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <map>
using namespace std;
using ll = long long;
const ll MOD = 1000000007ll;
ll pw(ll a, ll m) {
if (!m)
return 1;
if (m % 2)
return pw(a, m - 1) * a % MOD;
return pw(a * a % MOD, m >> 1);
}
signed main() {
ll n, m, k;
cin >> n >> m >> k;
map<ll, ll> mprow;
map<ll, ll> mpcellar;
bool row = true, cellar = true;
ll chess = -1;
for (ll aa = 0; aa < k; ++aa) {
char c;
int i, j;
cin >> c >> i >> j;
int t = int(c == '+');
if (mprow.find(i) != mprow.end() && mprow[i] != (j + t) % 2)
row = false;
else
mprow[i] = (j + t) % 2;
if (mpcellar.find(j) != mpcellar.end() && mpcellar[j] != (i + t) % 2)
cellar = false;
else
mpcellar[j] = (i + t) % 2;
//cout << i << ' ' << j << ' ' << t << ' ' << ": " << (i + j + t) % 2 << endl;
//cout << chess << ' ' << (i + j + t) % 2 << endl;
if (chess == -1 || chess == (i + j + t) % 2)
chess = (i + j + t) % 2;
else
chess = -2;
//cout << chess << ' ' << row << ' ' << cellar << endl;
}
ll ans = 0;
if (row)
ans += pw(2, n - mprow.size());
if (cellar)
ans += pw(2, m - mpcellar.size());
if (row && cellar) {
if (chess == -1) {
ans += MOD - 2;
} else if (chess != -2) {
ans += MOD - 1;
}
}
ans %= MOD;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |