# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589301 | 2022-07-04T12:21:37 Z | yutabi | Gondola (IOI14_gondola) | C++14 | 45 ms | 5960 KB |
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define MOD 1000000009 #define pb push_back typedef long long ll; typedef pair <int,int> ii; int valid(int n, int s[]) { set <int> st; int diff=-1; bool flag=0; for(int i=0;i<n;i++) { st.insert(s[i]); if(s[i]<=n) { int num=(s[i]+n-i)%n; if(diff!=-1 && diff!=num) { flag=1; } diff=num; } } if(st.size()!=n) { flag=1; } if(flag) { return 0; } return 1; } //---------------------- int replacement(int n, int ss[], int res[]) { vector <ii> s; int diff=0; for(int i=0;i<n;i++) { if(ss[i]<=n) { diff=(ss[i]+n-i-1)%n; } else { s.pb(ii(ss[i],i)); } } sort(s.begin(),s.end()); int ans=0; int curr=n; for(int i=0;i<s.size();i++) { res[ans]=((s[i].second+diff)%n)+1; ans++; curr++; while(curr<s[i].first) { res[ans]=curr; ans++; curr++; } } return ans; } //---------------------- ll fast_pow(ll a, ll b) { ll res=1; ll curr=a; while(b) { if(b%2) { res*=curr; res%=MOD; } b/=2; curr*=curr; curr%=MOD; } return res; } int countReplacement(int n, int ss[]) { if(valid(n,ss)==0) { return 0; } ll ans=1; vector <ii> s; int diff=-1; for(int i=0;i<n;i++) { if(ss[i]<=n) { diff=(ss[i]+n-i-1)%n; } else { s.pb(ii(ss[i],i)); } } sort(s.begin(),s.end()); ll curr=n; for(int i=0;i<s.size();i++) { ans*=fast_pow(s.size()-i, s[i].first-curr-1); ans%=MOD; curr=s[i].first; } if(diff==-1) { ans*=n; ans%=MOD; } 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 | 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 | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 10 ms | 2220 KB | Output is correct |
7 | Correct | 22 ms | 3652 KB | Output is correct |
8 | Correct | 18 ms | 3876 KB | Output is correct |
9 | Correct | 7 ms | 1364 KB | Output is correct |
10 | Correct | 23 ms | 4516 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 | 0 ms | 212 KB | Output is correct |
6 | Correct | 11 ms | 2260 KB | Output is correct |
7 | Correct | 22 ms | 3668 KB | Output is correct |
8 | Correct | 18 ms | 3992 KB | Output is correct |
9 | Correct | 5 ms | 1364 KB | Output is correct |
10 | Correct | 23 ms | 4472 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 11 ms | 2060 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 27 ms | 4600 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 | 0 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 |
# | 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 | 0 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 | 6 ms | 596 KB | Output is correct |
12 | Correct | 9 ms | 656 KB | Output is correct |
13 | Correct | 11 ms | 1180 KB | Output is correct |
14 | Correct | 6 ms | 596 KB | Output is correct |
15 | Correct | 20 ms | 2172 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 260 KB | Output is correct |
2 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 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 | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 32 ms | 4028 KB | Output is correct |
10 | Correct | 24 ms | 3412 KB | Output is correct |
11 | Correct | 9 ms | 1364 KB | Output is correct |
12 | Correct | 13 ms | 1684 KB | Output is correct |
13 | Correct | 3 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 | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 30 ms | 3924 KB | Output is correct |
10 | Correct | 24 ms | 3408 KB | Output is correct |
11 | Correct | 8 ms | 1364 KB | Output is correct |
12 | Correct | 14 ms | 1688 KB | Output is correct |
13 | Correct | 3 ms | 596 KB | Output is correct |
14 | Correct | 38 ms | 5328 KB | Output is correct |
15 | Correct | 45 ms | 5960 KB | Output is correct |
16 | Correct | 7 ms | 1308 KB | Output is correct |
17 | Correct | 28 ms | 4172 KB | Output is correct |
18 | Correct | 15 ms | 2740 KB | Output is correct |