# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722668 | 2023-04-12T14:28:04 Z | Yell0 | Gondola (IOI14_gondola) | C++17 | 61 ms | 6348 KB |
#include <bits/stdc++.h> #include "gondola.h" using namespace std; typedef long long ll; const int MOD=1e9+9; int valid(int n,int inputSeq[]) { vector<int> ogIdx(n+2); set<int> usedNew; bool f=0; for(int i=0;i<n;++i) { if(!f&&inputSeq[i]<=n) { f=1; ogIdx[inputSeq[i]]=i; for(int j=1;j<n;++j) ogIdx[(inputSeq[i]-1+j)%n+1]=(i+j)%n; } else if(inputSeq[i]<=n) { if(ogIdx[inputSeq[i]]!=i) return 0; } else { if(usedNew.count(inputSeq[i])) return 0; usedNew.insert(inputSeq[i]); } } return 1; } int replacement(int n,int gondolaSeq[],int replacementSeq[]) { vector<pair<int,int>> news; vector<int> og(n); for(int i=0;i<n;++i) if(gondolaSeq[i]>n) news.push_back({gondolaSeq[i],i}); sort(news.begin(),news.end()); bool f=0; for(int i=0;i<n;++i) { if(gondolaSeq[i]<=n) { f=1; og[i]=gondolaSeq[i]; for(int j=1;j<n;++j) og[(i+j)%n]=(og[i]-1+j)%n+1; break; } } if(!f) for(int i=0;i<n;++i) og[i]=i+1; int repi=0,currRep=n; for(int i=0;i<news.size();++i) { replacementSeq[repi++]=og[news[i].second]; ++currRep; while(currRep<news[i].first) replacementSeq[repi++]=currRep++; } return repi; } int countReplacement(int n,int inputSeq[]) { if(!valid(n,inputSeq)) return 0; vector<int> news; for(int i=0;i<n;++i) if(inputSeq[i]>n) news.push_back(inputSeq[i]); sort(news.begin(),news.end()); auto qpow=[&](ll x,int e) { ll res=1,mult=x; for(int i=0;(1<<i)<=e;++i) { if((1LL<<i)&e) res=res*mult%MOD; mult=mult*mult%MOD; } return res; }; ll ans=(news.size()==n?n:1); int prev=n; for(int i=0;i<news.size();++i) { ans=ans*qpow(news.size()-i,news[i]-prev-1)%MOD; prev=news[i]; } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 5 ms | 596 KB | Output is correct |
7 | Correct | 9 ms | 976 KB | Output is correct |
8 | Correct | 7 ms | 852 KB | Output is correct |
9 | Correct | 5 ms | 468 KB | Output is correct |
10 | Correct | 9 ms | 852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 4 ms | 596 KB | Output is correct |
7 | Correct | 9 ms | 980 KB | Output is correct |
8 | Correct | 10 ms | 852 KB | Output is correct |
9 | Correct | 3 ms | 468 KB | Output is correct |
10 | Correct | 9 ms | 880 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 5 ms | 596 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 9 ms | 980 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 8 ms | 852 KB | Output is correct |
12 | Correct | 9 ms | 916 KB | Output is correct |
13 | Correct | 13 ms | 1260 KB | Output is correct |
14 | Correct | 8 ms | 980 KB | Output is correct |
15 | Correct | 20 ms | 2248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 308 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 312 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 312 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 33 ms | 4044 KB | Output is correct |
10 | Correct | 25 ms | 3272 KB | Output is correct |
11 | Correct | 11 ms | 1748 KB | Output is correct |
12 | Correct | 13 ms | 1832 KB | Output is correct |
13 | Correct | 4 ms | 596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 37 ms | 4044 KB | Output is correct |
10 | Correct | 28 ms | 3164 KB | Output is correct |
11 | Correct | 11 ms | 1580 KB | Output is correct |
12 | Correct | 14 ms | 1972 KB | Output is correct |
13 | Correct | 3 ms | 596 KB | Output is correct |
14 | Correct | 59 ms | 5588 KB | Output is correct |
15 | Correct | 61 ms | 6348 KB | Output is correct |
16 | Correct | 9 ms | 1420 KB | Output is correct |
17 | Correct | 35 ms | 4380 KB | Output is correct |
18 | Correct | 23 ms | 2512 KB | Output is correct |