이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, m, k;
set<int> se, see;
set<int> se0, se1, se2, se3;
int binpw(int base, int pw){
int ans = 1;
while(pw){
if(pw & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
pw >>= 1;
}
return ans;
}
void process(){
cin >> n >> m >> k;
for(int i = 1; i <= k; i++){
int x, y;
char c;
cin >> c >> x >> y;
se.insert(x);
bool ck1 = (y & 1), ck2 = (c == '+');
if(ck1 ^ ck2) se1.insert(x);
else se0.insert(x);
ck1 = (x & 1), ck2 = (c == '+');
if(ck1 ^ ck2) se2.insert(y);
else se3.insert(y);
see.insert(y);
}
bool ok = 1;
for(auto it : se){
ok &= (se0.find(it) == se0.end() || se1.find(it) == se1.end());
}
if(ok){
int temp = binpw(2, n - se.size());
int ways = (binpw(2, m - see.size()) + mod) % mod;
for(auto it : se2){
if(se3.find(it) != se3.end()){
ways = 0;
break;
}
}
bool ck0 = 1, ck1 = 1;
for(auto it : se2){
if(it & 1) ck1 = 0;
else ck0 = 0;
}
for(auto it : se3){
if(it & 1) ck0 = 0;
else ck1 = 0;
}
cout << (temp + ways - ck0 - ck1) % mod;
}
else{
for(auto it : se2){
if(se3.find(it) != se3.end()){
cout << 0;
return;
}
}
cout << binpw(2, m - se2.size() - se3.size());
}
}
signed main(){
ios_base::sync_with_stdio(0);
process();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |