Submission #912105

#TimeUsernameProblemLanguageResultExecution timeMemory
912105yellowtoadRemittance (JOI19_remittance)C++17
0 / 100
2 ms2492 KiB
#include <iostream>
using namespace std;

int n, a[1000010], b[1000010], cnt;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] != b[i]) cnt++;
	}
	for (int i = 1; i <= 50; i++) {
		if (cnt == 0) {
			cout << "Yes" << endl;
			return 0;
		}
		for (int j = 1; j < n; j++) {
			if (a[j] > b[j]+1) {
				if (a[j+1] == b[j+1]) cnt++;
				a[j+1] += (a[j]-b[j])/2;
				if (a[j+1] == b[j+1]) cnt--;
				a[j] -= (a[j]-b[j])/2*2;
				if (a[j] == b[j]) cnt--;
			}
		}
		if (a[n] > b[n]+1) {
			if (a[1] == b[1]) cnt++;
			a[1] += (a[n]-b[n])/2;
			if (a[1] == b[1]) cnt--;
			a[n] -= (a[n]-b[n])/2*2;
			if (a[n] == b[n]) cnt--;
		}
		/*for (int j = 1; j <= n; j++) cout << a[j] << " " << b[j] << endl;
		cout << endl;*/
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...