Submission #489538

# Submission time Handle Problem Language Result Execution time Memory
489538 2021-11-23T05:42:03 Z fhvirus Remittance (JOI19_remittance) C++17
0 / 100
1 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int, int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
template<class I> bool chmin(I&a, I b){ return a > b ? (a=b, true) : false; }
template<class I> bool chmax(I&a, I b){ return a < b ? (a=b, true) : false; }
#ifdef OWO
#define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x){ cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

const int kN = 1000001;
const int kL = 30;
int N, A[kN], B[kN];

void gg(){
	cout << "No\n";
	exit(0);
}
void good(){
	cout << "Yes\n";
	exit(0);
}

void input(){
	cin >> N;
	for(int i = 1; i <= N; ++i)
		cin >> A[i] >> B[i];
}

int nxt(int i){ return i == N ? 1 : i+1; }

void solve(){
	for(int k = 0; k < 20; ++k){
		for(int i = 1; i <= N; ++i){
			if(A[i] > B[i]){
				int t = A[i] - B[i];
				if(t & 1) --t;
				A[ nxt(i) ] += (t>>1);
				A[i] -= t;
			}
		}
	}

	bool all = true;
	for(int i = 1; i <= N; ++i)
		all &= (A[i] == B[i]); 
	if(all) good();

	all = true;
	for(int i = 1; i <= N; ++i)
		all &= (A[i] == B[i]+1);
	if(all and *min_element(A+1, A+N+1) > 1) good();

	gg();
	return;
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	input();
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Incorrect 0 ms 204 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Incorrect 0 ms 204 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Incorrect 0 ms 204 KB Output isn't correct
9 Halted 0 ms 0 KB -