This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, K; cin >> N >> M >> K;
V<array<int, 3>> A(K);
for(int i = 0; i < K; i++) {
char ch; int r, c; cin >> ch >> r >> c; --r, --c;
A[i] = {r, c, ch == '+'};
}
auto POW = [&](ll a, ll p) {
if (p < 0) return 0LL;
ll ans = 1;
for(; p; p /= 2, a = (a * a) % MOD) if (p & 1) ans = (ans * a) % MOD;
return ans;
};
int ways = 0;
ll ans = 0;
for(int i = 0; i < 2; i++) {
unordered_set<int> R; unordered_map<int, int> PR;
int res = 0;
for(auto& v : A) {
auto [r, c, x] = v;
int p = (r ^ c) & 1;
int pr = p ^ x;
// cout << r << " " << c << " => " << x << " " << pr << endl;
if (R.count(r)) {
// cout << pr << " " << PR[r] << endl;
if (pr != PR[r]) res = -1;
} else R.insert(r), PR[r] = pr;
swap(v[0], v[1]);
}
if (res != -1) {
ways++;
ans += POW(2, N - sz(R));
// cout << sz(R) << endl;
}
swap(N, M);
}
if (ways == 2) ans--;
if (K == 0) ans--;
cout << (ans + MOD) % MOD << nl;
exit(0-0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |