Submission #48767

#TimeUsernameProblemLanguageResultExecution timeMemory
48767dooweyGondola (IOI14_gondola)C++14
90 / 100
27 ms14152 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; typedef pair<int,int> pii; #define fi first #define se second #define mp make_pair const int N = (int)25e4 + 1293; int valid(int n, int inputSeq[]) { int cnt[N]; for(int j = 0;j < N;j ++ ) cnt[j] = 0; int rest[n]; int maz = (int)4e5 + 12345; for(int i = 0; i < n;i ++){ cnt[inputSeq[i]]++; if(cnt[inputSeq[i]] >= 2) return 0; maz = min(maz, inputSeq[i]); rest[i] = inputSeq[i]; } if(maz > n) return 1; int p,j; for(int i = 0;i < n;i ++ ){ if(rest[i] <= n){ p = rest[i]+1; j = i+1; j %= N; while(p <= n){ rest[j] = p; p++; j++; j%=n; } p = 1; while(p < rest[i]){ rest[j] = p; j++; j %= n; p++; } break; } } for(int i = 0; i < n;i ++){ if(inputSeq[i] <= n){ if(rest[i] != inputSeq[i]) return 0; } } return 1; } //---------------------- int replacement(int n, int gondolas[], int replacementSeq[]) { int rx = 0; int start[n]; bool is = false; for(int i = 0;i < n;i ++){ if(gondolas[i] > n) is = true; if(gondolas[i] <= n) rx = i; } if(is == false) return 0; int ini; if(gondolas[rx] > n) start[rx] = 1; else start[rx] = gondolas[rx]; int p = start[rx] + 1; ini = start[rx]; rx ++ ; while(p <= n){ rx %= n; start[rx] = p; rx++; p++; } p = 1; rx %= n; while(p < ini){ start[rx] = p; p++; rx++; rx %= n; } vector<pii>qq; for(int i = 0;i < n;i ++){ if(start[i] < gondolas[i]){ qq.push_back(mp(gondolas[i],i)); } } sort(qq.begin(),qq.end()); int mak; int ii = n + 1; int ix; int sz = 0; for(auto x : qq){ mak = x.fi; ix = x.se; replacementSeq[sz] = start[ix]; sz++; start[ix] = ii; ii++; while(start[ix] < mak){ replacementSeq[sz] = start[ix]; start[ix] = ii; sz++; ii++; } ii = mak + 1; } return sz; } //---------------------- const int MOD = (int)1e9 + 9; int powr(int n,int k){ if(k == 0) return 1; int hf = powr(n,k/2); hf = (1LL * hf * hf) % MOD; if(k&1) hf = (1LL * hf * n) % MOD; return hf; } int countReplacement(int n, int inputSeq[]) { if(!valid(n,inputSeq)){ return 0; } int ans = 1; int mn = (int)1e9 + 999; for(int i = 0;i < n;i ++) mn = min(mn,inputSeq[i]); if(mn > n) ans = n; // n cylcic rotations vector<int>nex; nex.push_back(n); for(int i = 0;i < n;i ++) if(inputSeq[i] > n) nex.push_back(inputSeq[i]); sort(nex.begin(),nex.end()); int tk = (int)nex.size() - 1; for(int i = 1;i < (int)nex.size(); i ++){ ans = (1LL * ans * powr(tk,nex[i] - nex[i - 1] - 1)) % MOD; --tk; } return ans; }
#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...