Submission #320136

#TimeUsernameProblemLanguageResultExecution timeMemory
320136lukameladzeGondola (IOI14_gondola)C++14
55 / 100
45 ms8300 KiB
# include <bits/stdc++.h> # include <gondola.h> using namespace std; long long n,mp[300005],idx,a[300005],b[300005],x1,x22,x2,num,x11,mx,ans[300005],cnt; pair <long long , long long > x; long long y; multiset <pair <long long , long long > > ms; int valid(int n , int a[]) { //cin>>n; idx=-1; for (int i=0; i<n; i++) { // cin>>a[i]; if (mp[a[i]]) y=1; mp[a[i]]=1; if (a[i]<=n) idx=i; } if (y==1) { return 0; } if (idx==-1) { return 1; } num=a[idx]; for (int i=idx+1; i<n; i++) { num++; if (num==n+1) num=1; if (a[i]<=n && a[i]!=num) { return 0; } } for (int i=0; i<idx; i++) { num++; if (num==n+1) num=1; if (a[i]<=n && a[i]!=num) { return 0; } } return 1; } int replacement(int n, int a[], int ans[]) { idx=-1; for (int i=0; i<n; i++) { mp[a[i]]=1; if (a[i]<=n) idx=i; } if (idx==-1) { for (int i=0; i<n; i++) b[i]=i+1; for (int i=0; i<n; i++) { ms.insert({a[i],b[i]}); } x2=n; while (ms.size()) { x=*ms.begin(); x11=x.first; x22=x.second; if (x11!=x22) { ans[cnt]=x22; cnt++; x2++; } else { ms.erase(ms.find({x11,x22})); continue; } while (x11>x2) { ans[cnt]=x2; cnt++; x2++; } x2=x11; ms.erase(ms.find({x11,x22})); } } else { b[idx]=a[idx]; num=a[idx]; for(int i=idx+1; i<n; i++) { num++; if (num==n+1) num=1; b[i]=num; } for (int i=0; i<n; i++) { num++; if (num==n+1) num=1; b[i]=num; } for (int i=0; i<n; i++) { ms.insert({a[i],b[i]}); } x2=n; while (ms.size()) { x=*ms.begin(); x11=x.first; x22=x.second; if (x11!=x22) { ans[cnt]=x22; cnt++; x2++; } else { ms.erase(ms.find({x11,x22})); continue; } while (x11>x2) { ans[cnt]=x2; cnt++; x2++; } x2=x11; ms.erase(ms.find({x11,x22})); } } return cnt; } int countReplacement(int n, int inputSeq[]) { return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...