Submission #132717

# Submission time Handle Problem Language Result Execution time Memory
132717 2019-07-19T11:48:48 Z youngyojun Plus Minus (BOI17_plusminus) C++11
0 / 100
2 ms 256 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MOD = 1000000007;
const int MAXN = 100055;

ll pw(ll n, ll k) {
	ll r = 1; for(; k; k >>= 1) {
		if(k&1) r = n * r % MOD;
		n = n * n % MOD;
	}
	return r;
}

int O[MAXN];
int A[MAXN], B[MAXN];
bitset<MAXN> C;

ll Ans;
int H, W, N;

void process() {
	iota(O, O+N+1, 0);
	sort(O+1, O+N+1, [&](int a, int b) {
		return A[a] < A[b];
	});

	int cnt = 0;
	for(int s = 1, e; s <= N; cnt++, s = e) {
		for(e = s+1; e <= N && A[O[e]] == A[O[s]]; e++);
		bool isOdd = false, isEven = false;
		for(int oi = s, i, t; oi < e; oi++) {
			i = O[oi];
			t = A[i] + B[i] + (C[i] ? 1 : 0);
			((t&1) ? isOdd : isEven) = true;
		}
		if(isOdd && isEven) return;
	}
	Ans += pw(2, H-cnt);
	if(MOD <= Ans) Ans -= MOD;
}

void minusOne() {
	bool isOdd = false, isEven = false;
	for(int i = 1, t; i <= N; i++) {
		t = A[i] + B[i] + (C[i] ? 1 : 0);
		((t&1) ? isOdd : isEven) = true;
	}
	if(isOdd != isEven) Ans--;
	if(Ans < 0) Ans = MOD-1;
}

int main() {
	scanf("%d%d%d", &H, &W, &N);
	for(int i = 1; i <= N; i++) {
		char c;
		scanf(" %c%d%d", &c, &A[i], &B[i]);
		C[i] = '+' == c;
	}

	process();
	swap(H, W);
	for(int i = 1; i <= N; i++) swap(A[i], B[i]);
	process();
	
	minusOne();

	cout << Ans << endl;
	return 0;
}

Compilation message

plusminus.cpp: In function 'int main()':
plusminus.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &H, &W, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
plusminus.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d%d", &c, &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -