# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
165380 |
2019-11-26T16:54:00 Z |
cfalas |
Gondola (IOI14_gondola) |
C++14 |
|
97 ms |
8124 KB |
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000009
#define ll long long
int valid(int n, int a[]){
map<int, bool> used;
for(int i=0;i<n;i++){
if(used[a[i]]) return 0;
used[a[i]] = true;
}
int s = 0;
for(int i=0;i<n;i++){
if(a[i]<=n){
s = i;
break;
}
}
for(int i=0;i<n;i++){
if(a[i]<=n && (a[i]+(s-i) - 1 + n)%n + 1 != a[s]) return 0; }
return 1;
}
//----------------------
int replacement(int n, int a[], int ans[]){
int apos=-1, av;
int maxf=0;
int minf = 0;
unordered_map<int, int> m;
for(int i=0;i<n;i++){
if(a[i]<=n) apos = i, av=a[i];
else m[a[i]] = i+1;
maxf = max(maxf, a[i]);
if(a[minf]>a[i]) minf = i;
}
if(apos==-1){
apos = minf;
av = 1;
}
queue<int> q;
int l=0;
for(int i=n+1;i<=maxf;i++){
if(m[i]){
int c = l - 1;
ans[l] = (n + av - (apos - m[i] + 1) - 1) % n + l - c;
l++;
//cout<<apos<<" "<<m[i]<<" "<<av<<endl;
while(!q.empty()){
ans[l] = q.front();
q.pop();
l++;
}
}
else q.push(i);
}
return l;
}
//----------------------
ll mpow(ll a, ll b){
if(b==0) return 1;
if(b==1) return a;
ll z = mpow(a, b/2);
z*=z;
z%=MOD;
if(b%2) z*=a;
z%=MOD;
return z;
}
int countReplacement(int n, int a[]){
if(!valid(n, a)) return 0;
int act=-1;
int un=0;
for(int i=0;i<n;i++){
if(a[i]<=n) act = i;
else un++;
}
sort(a, a+n);
ll ans=1;
if(act==-1) ans*=n;
ll prev = n+1;
for(int i=0;i<n-1 && un>=1;i++){
if(a[i]<=n) continue;
//cout<<un<<" "<<mpow(un, a[i+1]-a[i]-1)<<" "<<a[i]<<" "<<a[i+1]<<endl;
ans *= mpow(un, a[i]-prev);
ans%=MOD;
prev = a[i]+1;
un--;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
21 ms |
2428 KB |
Output is correct |
7 |
Correct |
14 ms |
632 KB |
Output is correct |
8 |
Correct |
36 ms |
4344 KB |
Output is correct |
9 |
Correct |
13 ms |
1656 KB |
Output is correct |
10 |
Correct |
51 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
24 ms |
2424 KB |
Output is correct |
7 |
Correct |
15 ms |
1272 KB |
Output is correct |
8 |
Correct |
36 ms |
4344 KB |
Output is correct |
9 |
Correct |
13 ms |
1660 KB |
Output is correct |
10 |
Correct |
52 ms |
5108 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
26 ms |
2132 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
68 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
632 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
12 ms |
888 KB |
Output is correct |
12 |
Correct |
13 ms |
1144 KB |
Output is correct |
13 |
Correct |
31 ms |
4100 KB |
Output is correct |
14 |
Correct |
12 ms |
1020 KB |
Output is correct |
15 |
Correct |
55 ms |
8124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
64 ms |
4668 KB |
Output is correct |
10 |
Correct |
49 ms |
3832 KB |
Output is correct |
11 |
Correct |
18 ms |
1656 KB |
Output is correct |
12 |
Correct |
22 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
60 ms |
4472 KB |
Output is correct |
10 |
Correct |
47 ms |
3832 KB |
Output is correct |
11 |
Correct |
18 ms |
1656 KB |
Output is correct |
12 |
Correct |
22 ms |
1884 KB |
Output is correct |
13 |
Correct |
6 ms |
760 KB |
Output is correct |
14 |
Correct |
76 ms |
5368 KB |
Output is correct |
15 |
Correct |
97 ms |
6008 KB |
Output is correct |
16 |
Correct |
14 ms |
1400 KB |
Output is correct |
17 |
Correct |
57 ms |
4156 KB |
Output is correct |
18 |
Correct |
31 ms |
2556 KB |
Output is correct |