이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;
ll N, A[1000005], B[1000005], bal, afk, pos;
string ans;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N;
	for (ll i = 1; i <= N; i++) cin >> A[i] >> B[i];
	
	bal = 0;
	afk = 0;
	pos = 1;
	
	while (afk <= N) {
		A[pos] += bal;
		if (A[pos] > B[pos]) {
			if (A[pos] % 2 == B[pos] % 2) {
				bal = (A[pos] - B[pos]) / 2;
				A[pos] = B[pos];
			} else if (B[pos] != 0) {
				bal = (A[pos] - B[pos] + 1) / 2;
				A[pos] = B[pos] - 1;
			} else {
				bal = (A[pos] - B[pos] - 1) / 2;
				A[pos] = 1;
			}
		} else bal = 0;
		if (bal > 0) afk = 0;
        else afk++;
		if (pos == N) pos = 1;
		else pos++;
	}
	
	ans = "Yes";
	if (bal != 0) ans = "No";
	for (ll i = 1; i <= N; i++) {
		if (A[i] != B[i]) ans = "No";
	}
	
	cout << ans;
		
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |