답안 #489463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489463 2021-11-23T02:57:30 Z fhvirus 송금 (JOI19_remittance) C++17
0 / 100
0 ms 332 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 input(){
	cin >> N;
	for(int i = 1; i <= N; ++i)
		cin >> A[i] >> B[i];
}

void solve(){
	for(int l = 0; l <= kL; ++l){
		for(int i = 1; i <= N; ++i){
			if((A[i] ^ B[i]) & (1<<l)){
				// borrow from other
				for(int j = (i==1 ? N : i-1), v = (1<<(l+1)); ; j = (j == 1 ? N : j-1) ){
					if(j == i) gg();
					if(v > (1<<kL)) gg();
					if(A[j] - B[j] >= v){
						A[j] -= v;
						A[i] += (1<<l);
						break;
					}
					v = (v - (A[j] - B[j])) * 2;
				}
			}
		}
	}

	for(int i = 1; i <= N; ++i)
		if(A[i] != B[i]) gg();
	cout << "Yes\n";

	return;
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	input();
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -