제출 #1349527

#제출 시각아이디문제언어결과실행 시간메모리
1349527Jawad_Akbar_JJPlus Minus (BOI17_plusminus)C++20
54 / 100
311 ms31804 KiB
#include <iostream>
#include <map>

using namespace std;
int mod = 1e9 + 7;
map<int, int> cX[2][2], cY[2][2], A, B;
int cnt[2][2];

int power(int a, int b){
	if (b == 0)
		return 1;
	int ans = power(a, b / 2);
	ans = 1LL * ans * ans % mod;
	if (b & 1)
		ans = 1LL * ans * a % mod;
	return ans;
}

int main(){
	int n, m, k, t1 = 1, t2 = 1, t3 = 1;
	cin>>n>>m>>k;

	for (int i=1, x, y, bl;i<=k;i++){
		char c;
		cin>>c>>x>>y;
		bl = (c == '+');

		A[x], B[y];
		
		cX[bl][y % 2][x]++;
		cY[bl][x % 2][y]++;
		if (cX[bl][0][x] and cX[bl][1][x])
			t1 = 0;
		if (cX[bl][y % 2][x] and cX[!bl][y % 2][x])
			t1 = 0;
		if (cY[bl][0][y] and cX[bl][1][y])
			t2 = 0;
		if (cY[bl][x % 2][y] and cY[!bl][x % 2][y])
			t2 = 0;

		cnt[bl][(x+y)%2]++;
		if (cnt[bl][0] and cnt[bl][1])
			t3 = 0;
	}

	int Ans = power(2, n - A.size()) * t1 + power(2, m - B.size()) * t2 - t3 * (k == 0 ? 2 : 1);

	// cout<<t1<<' '<<t2<<' '<<t3<<endl;

	cout<<Ans % mod<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...