# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209595 | 2020-03-14T18:27:42 Z | Lukoloz | Gondola (IOI14_gondola) | C++14 | 77 ms | 5112 KB |
#include <bits/stdc++.h> #include "gondola.h" #define ll long long #define ff first #define ss second #define pb push_back #define MAXN 100005 #define NASH 1000000009LL using namespace std; ll pow(ll i, ll j){ if (j==0) return 1; if (j==1) return i; ll ret=pow(i,j/2); ret=(ret*ret)%NASH; if (j%2) ret=(ret*i)%NASH; return ret; } int valid(int n, int inputSeq[]){ map <int,bool> fl; int tdif,dif=-1; for (int i=0; i<n; i++){ if (fl[inputSeq[i]]==1) return 0; fl[inputSeq[i]]=1; if (inputSeq[i]<=n){ tdif=inputSeq[i]-1-i; if (tdif<0) tdif+=n; if (dif!=-1 && tdif!=dif) return 0; dif=tdif; } } return 1; } int replacement(int n, int gondolaSeq[], int replacementSeq[]){ int dif=0,mx=0,mxi; for (int i=0; i<n; i++){ if (gondolaSeq[i]>mx){ mx=gondolaSeq[i]; mxi=i; } if (gondolaSeq[i]<=n){ dif=gondolaSeq[i]-1-i; if (dif<0) dif+=n; } } for (int i=0; i<mx-n; i++) replacementSeq[i]=0; for (int i=0; i<n; i++){ if (i==mxi || gondolaSeq[i]<=n) continue; replacementSeq[gondolaSeq[i]-n-1]=(i+dif)%n+1; } mxi=(mxi+dif)%n+1; for (int i=0; i<mx-n; i++){ if (replacementSeq[i]!=0) continue; replacementSeq[i]=mxi; mxi=i+n+1; } // for (int i=0; i<mx-n; i++) cout<<replacementSeq[i]<<" "; cout<<endl; return mx-n; } int countReplacement(int n, int inputSeq[]){ if (!valid(n,inputSeq)) return 0; ll ans=1; vector <int> v; for (int i=0; i<n; i++) if (inputSeq[i]>n) v.pb(inputSeq[i]); if (v.size()==n) v.pb(n-1); else v.pb(n); sort(v.begin(),v.end()); for (int i=1; i<v.size(); i++){ ans=(ans*pow((ll)v.size()-i,(ll)(v[i]-v[i-1]-1)))%NASH; } return (int)ans; } // int main(){ // // ifstream cin("magari.txt"); // int n; // cin>>n; // int arr[n]; // for (int i=0; i<n; i++) cin>>arr[i]; // cout<<countReplacement(n,arr)<<endl; // }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 19 ms | 2168 KB | Output is correct |
7 | Correct | 17 ms | 632 KB | Output is correct |
8 | Correct | 34 ms | 3960 KB | Output is correct |
9 | Correct | 13 ms | 1528 KB | Output is correct |
10 | Correct | 41 ms | 4600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 20 ms | 2168 KB | Output is correct |
7 | Correct | 17 ms | 632 KB | Output is correct |
8 | Correct | 33 ms | 3960 KB | Output is correct |
9 | Correct | 14 ms | 1532 KB | Output is correct |
10 | Correct | 40 ms | 4600 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Correct | 10 ms | 504 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 18 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 380 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 4 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 15 ms | 632 KB | Output is correct |
12 | Correct | 17 ms | 632 KB | Output is correct |
13 | Correct | 17 ms | 1144 KB | Output is correct |
14 | Correct | 15 ms | 632 KB | Output is correct |
15 | Correct | 23 ms | 2172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 280 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 296 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 54 ms | 4088 KB | Output is correct |
10 | Correct | 46 ms | 3448 KB | Output is correct |
11 | Correct | 19 ms | 1400 KB | Output is correct |
12 | Correct | 22 ms | 1656 KB | Output is correct |
13 | Correct | 9 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 4 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 256 KB | Output is correct |
9 | Correct | 54 ms | 4088 KB | Output is correct |
10 | Correct | 45 ms | 3448 KB | Output is correct |
11 | Correct | 18 ms | 1400 KB | Output is correct |
12 | Correct | 23 ms | 1656 KB | Output is correct |
13 | Correct | 8 ms | 636 KB | Output is correct |
14 | Correct | 67 ms | 4604 KB | Output is correct |
15 | Correct | 77 ms | 5112 KB | Output is correct |
16 | Correct | 15 ms | 1148 KB | Output is correct |
17 | Correct | 50 ms | 3576 KB | Output is correct |
18 | Correct | 29 ms | 2168 KB | Output is correct |