# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316945 | neki | 곤돌라 (IOI14_gondola) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#include <"gondola.h">
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 200100
#define pa pair<ll, ll>
#define ld long double
#define k 450
int valid(int n, int inputSeq[]){
vc<pa> tes;
map<ll, ll> cnt;loop(i, 0, n) cnt[inputSeq[i]]++;
fore(v, cnt) if(v.se>1) return 0;
loop(i, 0, n) if(inputSeq[i]<=n)tes.ps(make_pair(i, inputSeq[i]));
if(tes.size()==0) return 1;
loop(i, 0, tes.size()) if((tes[(i+1)%n].fi-tes[i%n].fi+n)%n!=(tes[(i+1)%n].se-tes[i%n].se+n)%n) return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
ll zac=1, cnt=0;
map<ll, ll> poi;
loop(i, 0, n){
if(gondolaSeq[i]<=n) zac=(gondolaSeq[i]-i+n)%n;
else poi[gondolaSeq[i]]=i;
}
if(poi.size()==0) return 0;
vc<ll> cur(n, 0);
loop(i, 0, n){
cur[i]=(zac+i)%n;
if(cur[i]==0) cur[i]=n;
}
loop(j, n+1, poi.begin()->fi+1) replacementSeq[cnt++]=cur[poi.begin()->se]++;
for(auto v=poi.begin();v!=poi.end();++v){
auto ne=v; ++ne;
if(ne==poi.end()) break;
loop(j, v->fi+1, ne->fi+1) replacementSeq[cnt++]=cur[poi.begin()->se], cur[poi.begin()->se]=j;
}
auto bac=poi.end();bac--;
return bac->fi - n;
}