제출 #1129698

#제출 시각아이디문제언어결과실행 시간메모리
1129698MuhammetPlus Minus (BOI17_plusminus)C++20
100 / 100
102 ms9828 KiB
#include "bits/stdc++.h"

using namespace std;

#define ll long long

const int M = 1e9+7;

int n, m, k, ans;

map <int,int> mpr, mpc;

ll f(int x){
	if(x == 0) return 1;
	if(x % 2 == 0) return (f(x/2) * f(x/2) * 1LL) % M;
	else return (f(x/2) * f(x/2) * 2 * 1LL) % M;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);

	cin >> n >> m >> k;
	int n1 = n, m1 = m;
	bool tr = 0, tr1 = 0, tr2 = 1, tr3 = 1;
	for(int i = 1; i <= k; i++){
		char c;
		int x, y;
		cin >> c >> x >> y;
		int a = (c == '+' ? 1 : 0);
		if((x+y) % 2 != a) tr2 = 0;
		if((x+y) % 2 != a^1) tr3 = 0;
		if(!(y % 2)) a = (a+1)%2;
		a++;
		if(mpr[x] == 0) mpr[x] = a, n--;
		else {
			if(mpr[x] != a) tr = 1;
		}
		a = (c == '+' ? 1 : 0);
		if(!(x % 2)) a = (a+1)%2;
		a++;
		if(mpc[y] == 0) mpc[y] = a, m--;
		else {
			if(mpc[y] != a) tr1 = 1;
		}
	}
	ll ans = 0;
	if(!tr) ans += f(n);
	ans %= M;
	if(!tr1) ans += f(m);
	ans %= M;
	ans -= (tr2 + tr3);
	cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...