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;
#define int int64_t
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 1e9+7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N, M, K; cin >> N >> M >> K;
vector<ar<int,3>> A(K);
for (auto &i : A) {
char ch; cin >> ch >> i[1] >> i[2];
i[0] = ch == '+';
}
map<int,vector<ar<int, 2>>> remdi;
for (auto &[t, x, y] : A) remdi[x].push_back({y, t});
int sol1 = N;
for (auto [x, v] : remdi) {
int sy = v[0][0], st = v[0][1];
for (auto [y, t] : v) if ((abs(y - sy) & 1) != abs(t - st)) sol1 = -1;
sol1--;
}
remdi.clear(); int sol2 = M;
for (auto &[t, x, y] : A) remdi[y].push_back({x, t});
for (auto [y, v] : remdi) {
int sx = v[0][0], st = v[0][1];
for (auto [x, t] : v) if ((abs(x - sx) & 1) != abs(t - st)) sol2 = -1;
sol2--;
}
auto pow = [&](int p)->int {
if (p < 0) return 0LL;
int res = 1, cur = 2;
while (p) {
if (p & 1) res = (res * cur) % MOD;
cur = (cur * cur) % MOD; p >>= 1;
}
return res;
};
cout << pow(sol1) + pow(sol2) - (sol1 >= 0 && sol2 >= 0) - (K == 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... |