Submission #253781

# Submission time Handle Problem Language Result Execution time Memory
253781 2020-07-28T16:48:41 Z kshitij_sodani Remittance (JOI19_remittance) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
llo n;
pair<llo,llo> it[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;

	for(llo i=0;i<n;i++){
		cin>>it[i].a>>it[i].b;
	}
	llo su=0;
	llo cur=1;
	for(llo i=1;i<n;i++){
		su+=(it[i].a-it[i].b)*cur;
		cur*=2;
	}
	su+=cur*(it[0].a-it[0].b);
	cur*=2;
	cur-=1;

	if(su<0){
		cout<<"No"<<endl;
	}
	else{
		if(su%cur>0){
			cout<<"No"<<endl;
		}
		else{
			llo ac=su/cur;
			vector<int> val;
			val.pb(ac);
			for(llo i=1;i<n;i++){
				llo cc=it[i].a-it[i].b+ac;
				if(cc<0){
					cout<<"No"<<endl;
					return 0;
				}
				if(cc%2>0){
					cout<<"No"<<endl;
					return 0;
				}
				ac=cc/2;
				val.pb(ac);
			}
			set<pair<int,int>> kk;
			for(int i=0;i<n;i++){
				kk.insert({-it[i].a,i});
			}
			int st=1;
			while(kk.size()){
				pair<int,int> no=*kk.begin();
				if(val[no.b]==0){
					kk.erase(no);
					continue;
				}
				no.a=-no.a;
				if(no.a<=1){
					st=0;
					cout<<"No"<<endl;
					return 0;
					break;
				}
				val[no.b]-=1;
				it[no.b].a-=2;
				kk.erase(no);
				kk.erase({-it[(no.b+1)%n].a,(no.b+1)%n});
				it[(no.b+1)%n].a+=1;
				kk.insert({-it[(no.b+1)%n].a,(no.b+1)%n});
				kk.insert({-it[no.b].a,no.b});
			}
			for(int i=0;i<n;i++){
				if(it[i].a!=it[i].b){
					cout<<"No"<<endl;
					return 0;
				}
			}

			cout<<"Yes"<<endl;
		}
	}







	return 0;
}

Compilation message

remittance.cpp: In function 'int main()':
remittance.cpp:57:8: warning: variable 'st' set but not used [-Wunused-but-set-variable]
    int st=1;
        ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -