Submission #135702

#TimeUsernameProblemLanguageResultExecution timeMemory
135702khsoo01Plus Minus (BOI17_plusminus)C++11
100 / 100
237 ms15084 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n, m, k, tot, rc, cc, ans;
map<ll, ll> row, col;
bool rv, cv, tv;

ll two (ll A) {
	if(!A) return 1;
	ll ret = two(A/2);
	ret = ret * ret % mod;
	if(A&1) ret = ret * 2 % mod;
	return ret;
}

int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=k;i++) {
		ll A, B, C;
		char T[2];
		scanf("%s%lld%lld",T,&A,&B);
		C = (T[0] == '+');
		ll X = ((A^B^C)&1)+1;
		if(row[A]) {
			if(row[A] != X) rv = true;
		} else {
			row[A] = X;
			rc++;
		}
		if(col[B]) {
			if(col[B] != X) cv = true;
		} else {
			col[B] = X;
			cc++;
		}
		if(tot) {
			if(tot != X) tv = true;
		} else tot = X;
	}
	if(!rv) ans = (ans + two(n-rc)) % mod;
	if(!cv) ans = (ans + two(m-cc)) % mod;
	if(!tv) ans = (ans + mod - 1) % mod;
	if(!k) ans = (ans + mod -1) % mod;
	printf("%lld\n",ans);
}

Compilation message (stderr)

plusminus.cpp: In function 'int main()':
plusminus.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
plusminus.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s%lld%lld",T,&A,&B);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...