Submission #1210967

#TimeUsernameProblemLanguageResultExecution timeMemory
1210967nguynRemittance (JOI19_remittance)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 1e6 + 5;

int n;
int a[N];
int b[N];

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i] >> b[i];
    }
    while(1) {
    	bool ok = 0;
    	for (int i = 1; i <= n; i++) {
    		int nxt = i + 1;
    		if (nxt > n) nxt = 1; 
    		if ((a[i] - b[i]) >= 2) {
    			int t = (a[i] - b[i]) / 2;
    			a[i] -= 2 * t;
    			a[nxt] += t; 
    			ok = 1;
    		} 
    	}
	    // for (int i = 1; i <= n; i++) {
	    // 	cout << a[i] << ' ';
	    // }
	    // cout << '\n';
    	if (!ok) break;
    }
    while(1) {
    	bool ok = 0;
    	for (int i = 1; i <= n; i++) {
    		int nxt = i + 1;
    		if (nxt > n) nxt = 1;
    		if (a[i] > b[i]) {
    			a[i] -= 2;
    			a[nxt]++;
    			ok = 1;
    		}
    	}
    	if (!ok) break;
    } 
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
    	if (a[i] != b[i]) {
    		ok = 0;
    		break;
    	}
    }
    cout << (ok ? "Yes" : "No");
}

Compilation message (stderr)

remittance.cpp: In function 'int main()':
remittance.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
remittance.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...