이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
ll expo(ll base, int pow) {
ll ans = 1;
while (pow) {
if (pow & 1) ans = (ans * base) % MOD;
pow >>= 1;
base = (base * base) % MOD;
}
return ans;
}
ll count_ways(int n, int m, map<int, vector<pair<int, char>>> mp) {
for (auto& i : mp) {
bool sgn = (i.second[0].first & 1) ^ (i.second[0].second == '+');
for (pair<int, char> j : i.second) {
bool needed = (j.first & 1) ^ (j.second == '+');
if (sgn ^ needed) return 0;
}
}
return expo(2, n - mp.size());
}
int check_both(int n, int m, map<int, vector<pair<int, char>>> mp) {
if (mp.size() == 0) return 2;
bool sgn = (mp.begin()->first & 1) ^ (mp.begin()->second[0].first & 1) ^ (mp.begin()->second[0].second == '+');
for (auto& i : mp) {
for (pair<int, char> j : i.second) {
bool needed = (i.first & 1) ^ (j.first & 1) ^ (j.second == '+');
if (sgn ^ needed) return 0;
}
}
return 1;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
map<int, vector<pair<int, char>>> horiz, vert;
while (k--) {
char c;
int x, y;
cin >> c >> x >> y;
horiz[x].push_back({y, c});
vert[y].push_back({x, c});
}
cout << (count_ways(n, m, horiz) + count_ways(m, n, vert) - check_both(n, m, horiz)) % MOD;
return 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... |