이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll pw(ll a, ll b){
	ll ret = 1;
	while(b){
		if(b&1)ret = ret * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}
int main(){
	int n, m, k; cin >> n >> m >> k;
	vector<pair<char,pair<int,int>>> v(k);
	for(int i = 0; i < k; ++i){
		cin >> v[i].first >> v[i].second.first >> v[i].second.second, v[i].second.first--, v[i].second.second--;
	}
	ll ans = 0;
	{
		map<int,int> M;
		bool ok = 1;
		for(int i = 0; i < k; ++i){
			int x = ((v[i].second.second&1)^(v[i].first == '+'))+1;
			if(M[v[i].second.first]){
				if(M[v[i].second.first] != x)ok = 0;
				break;
			}
			M[v[i].second.first] = x;
		}
		if(ok)ans += pw(2,n-M.size());
	}
	{
		map<int,int> M;
		bool ok = 1;
		for(int i = 0; i < k; ++i){
			int x = ((v[i].second.first&1)^(v[i].first == '+'))+1;
			if(M[v[i].second.second]){
				if(M[v[i].second.second] != x)ok = 0;
				break;
			}
			M[v[i].second.second] = x;
		}
		if(ok)ans += pw(2,m-M.size());
	}
	{
		bool ok = 1;
		for(int i = 0; i < k; ++i){
			if(((v[i].second.first+v[i].second.second)&1) ^ (v[i].first == '-')){
				ok = 0;
				break;
			}
		}
		ans-=ok;
	}
	{
		bool ok = 1;
		for(int i = 0; i < k; ++i){
			if(((v[i].second.first+v[i].second.second)&1) ^ (v[i].first == '+')){
				ok = 0;
				break;
			}
		}
		ans-=ok;
	}
	cout << ans % MOD << '\n';
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |