# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852309 | 2023-09-21T14:55:03 Z | DobromirAngelov | Gondola (IOI14_gondola) | C++14 | 50 ms | 7580 KB |
#include "gondola.h" #include<bits/stdc++.h> using namespace std; const int MAXN=1e5+5; const int MOD=1e9+9; map<int,int> m; int valid(int n, int a[]) { for(int i=0;i<n;i++) { if(m[a[i]]!=0) return 0; m[a[i]]=1; } int mn=1e9, idx=-1; for(int i=0;i<n;i++) { if(a[i]<mn) { mn=a[i]; idx=i; } } if(mn<=n) { int cur=mn+1; for(int i=idx+1;i!=idx;i++) { if(i>=n) i-=n; if(a[i]<=n && a[i]!=cur) return 0; cur++; if(i==n-1) i=-1; } } return 1; } int b[MAXN]; vector<pair<int,int> > v; int replacement(int n, int a[], int replacementSeq[]) { int mn=1e9,idx=-1; for(int i=0;i<n;i++) { if(a[i]<mn) { mn=a[i]; idx=i; } } if(mn>n) { for(int i=0;i<n;i++) b[i]=i+1; } else { int cur=mn; b[idx]=cur++; for(int i=idx+1;i!=idx;i++) { if(i>=n) i-=n; if(cur>n) cur-=n; b[i]=cur++; if(i==n-1) i=-1; } } for(int i=0;i<n;i++) { if(a[i]>n) v.push_back({a[i],b[i]}); } sort(v.begin(), v.end()); int ptr=0; int cur=n; for(int i=0;i<v.size();i++) { replacementSeq[ptr++]=v[i].second; cur++; while(cur<v[i].first) { replacementSeq[ptr++]=cur++; } } return ptr; } int fastPow(int a,int pw) { long long ret=1; while(pw>0) { if(pw&1) ret=ret*a%MOD; a=(long long) a*a%MOD; pw/=2; } return ret; } int countReplacement(int n, int a[]) { if(!valid(n,a)) return 0; int mx=0; for(int i=0;i<n;i++) { mx=max(mx,a[i]); } if(mx==n) return 1; int mn=1e9,idx=-1; for(int i=0;i<n;i++) { if(a[i]<mn) { mn=a[i]; idx=i; } } if(mn>n) { for(int i=0;i<n;i++) b[i]=i+1; } else { int cur=mn; b[idx]=cur++; for(int i=idx+1;i!=idx;i++) { if(i>=n) i-=n; if(cur>n) cur-=n; b[i]=cur++; if(i==n-1) i=-1; } } for(int i=0;i<n;i++) { if(a[i]>n) v.push_back({a[i],b[i]}); } sort(v.begin(), v.end()); int ptr=0; int last=0; int cur=n; long long ans=1; for(int i=0;i<v.size();i++) { ptr++; cur++; while(cur<v[i].first) { ptr++; cur++; } ans=ans*fastPow(v.size()-i, ptr-last-1)%MOD; last=ptr; } if(mn>n) ans=ans*n%MOD; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 9 ms | 2140 KB | Output is correct |
7 | Correct | 6 ms | 604 KB | Output is correct |
8 | Correct | 18 ms | 3876 KB | Output is correct |
9 | Correct | 5 ms | 1368 KB | Output is correct |
10 | Correct | 21 ms | 4444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 9 ms | 2140 KB | Output is correct |
7 | Correct | 6 ms | 604 KB | Output is correct |
8 | Correct | 20 ms | 3924 KB | Output is correct |
9 | Correct | 6 ms | 1396 KB | Output is correct |
10 | Correct | 22 ms | 4492 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 13 ms | 2140 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 33 ms | 4668 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 424 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 504 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 6 ms | 860 KB | Output is correct |
12 | Correct | 6 ms | 1116 KB | Output is correct |
13 | Correct | 10 ms | 1752 KB | Output is correct |
14 | Correct | 6 ms | 860 KB | Output is correct |
15 | Correct | 15 ms | 2520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 32 ms | 5068 KB | Output is correct |
10 | Correct | 26 ms | 4316 KB | Output is correct |
11 | Correct | 10 ms | 1884 KB | Output is correct |
12 | Correct | 12 ms | 2312 KB | Output is correct |
13 | Correct | 3 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 360 KB | Output is correct |
3 | Correct | 1 ms | 360 KB | Output is correct |
4 | Correct | 0 ms | 532 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 564 KB | Output is correct |
9 | Correct | 34 ms | 5024 KB | Output is correct |
10 | Correct | 25 ms | 4424 KB | Output is correct |
11 | Correct | 10 ms | 1884 KB | Output is correct |
12 | Correct | 12 ms | 2296 KB | Output is correct |
13 | Correct | 3 ms | 860 KB | Output is correct |
14 | Correct | 42 ms | 6964 KB | Output is correct |
15 | Correct | 50 ms | 7580 KB | Output is correct |
16 | Correct | 11 ms | 1884 KB | Output is correct |
17 | Correct | 30 ms | 4996 KB | Output is correct |
18 | Correct | 16 ms | 3296 KB | Output is correct |