답안 #797294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797294 2023-07-29T08:56:10 Z fatemetmhr 송금 (JOI19_remittance) C++17
0 / 100
1 ms 340 KB
// Be name khoda // 

#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define pb     push_back
#define fi     first
#define se     second
#define mp     make_pair

typedef long long ll;

using namespace std;

const int maxn5 = 1e6 + 10;
const ll inf    = 1e18;

bool mark[maxn5];
ll a[maxn5], b[maxn5];
queue <int> q;

int n;
bool found = false;


void solve(int lev, int cnt){
	bool re = true;
	for(int i = 0; i < n; i++)
		re &= (a[i] == b[i]);
	if(re){
		found = true;
		return;
	}
	if(cnt == n)
		return;	
	for(int x = 2; x <= a[lev]; x+= 2){
		a[lev] -= x;
		a[(lev + 1)%n] += x / 2;
		solve((lev + 1) % n, 0);
		if(found)
			return;
		a[lev] += x;
		a[(lev + 1)%n] -= x / 2;
	}
	solve((lev + 1)%n, cnt + 1);

}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		sum += a[i];
	}
	//solve(0, 0);
	//cout << (found ? "Yes" : "No") << endl;
	//return 0;
	while(sum > 0){
		bool re = true;
		for(int i = 0; i < n; i++){
			if(a[i] > b[i]){
				int j = (i + 1) % n;
				ll w = (a[i] - b[i]) / 2 + ((a[i] - b[i]) % 2);
				a[j] += w;
				a[i] -= 2 * w;
				sum -= w;
				re = false;
			}
		}
		if(re){
			for(int i = 0; i < n; i++)
				re &= (a[i] == b[i]);
			if(!re)
				break;
			return cout << "Yes" << endl, 0;
		}
	}
	cout << "No" << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Incorrect 0 ms 212 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Incorrect 0 ms 212 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Incorrect 0 ms 212 KB Output isn't correct
29 Halted 0 ms 0 KB -