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 <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7; 
long long res_pw;
long long pw(long long x, long long expo) {
	res_pw = 1;
	while (expo) {
	    if (expo & 1) res_pw = res_pw * x % mod;
	    x = x * x % mod;
	    expo >>= 1;
	}
	return res_pw;
}
map<int, int> color_r, color_c;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, k, x, y, c, t; char raw_c; cin >> n >> m >> k;
	bool pass_r = 1, pass_c = 1, d = 0; int cnt_r = 0, cnt_c = 0, tmp = 0, ans = 0;
	for (int i = 1; i <= k; ++i) {
		cin >> raw_c >> x >> y; c = (raw_c == '+');
		t = ((x ^ y ^ c) & 1) + 1;
		if (color_r[x]) {if (color_r[x] != t) pass_r = 0;}
		else color_r[x] = t, ++cnt_r;
		if (color_c[y]) {if (color_c[y] != t) pass_c = 0;}
		else color_c[y] = t, ++cnt_c;
		if (tmp) {if (tmp != t) d = 1;}
		else tmp = t;
	}
	if (pass_r) ans = (ans + pw(2, n - cnt_r)) % mod;
	if (pass_c) ans = (ans + pw(2, m - cnt_c)) % mod;
	ans = (ans + mod - (!d) - (!k)) % mod;
	cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |