# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
208243 |
2020-03-10T12:15:33 Z |
Sorting |
Gondola (IOI14_gondola) |
C++14 |
|
33 ms |
2152 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
bool check_valid_pair(int lvalue, int rvalue, int n){
if(lvalue <= 0 || rvalue <= 0)
return false;
if(lvalue > n || rvalue > n)
return true;
if((lvalue + 1) % n != rvalue % n)
return false;
return true;
}
int valid(int n, int inputSeq[]){
if(n == 1)
return true;
for(int i = 0; i < n - 1; ++i)
if(!check_valid_pair(inputSeq[i], inputSeq[i + 1], n))
return false;
if(!check_valid_pair(inputSeq[n - 1], inputSeq[0], n))
return false;
sort(inputSeq, inputSeq + n);
for(int i = 0; i < n - 1; ++i)
if(inputSeq[i] == inputSeq[i + 1])
return false;
return true;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int start = 0;
for(int i = 0; i < n; ++i){
if(gondolaSeq[i] <= n){
start = i + 1 - gondolaSeq[i];
if(start < 0)
start += n;
break;
}
}
vector<pair<int, int>> v(n);
for(int i = 0; i < n; ++i)
v[i] = {gondolaSeq[i], i};
sort(v.begin(), v.end());
int cnt_replacement = 0, new_n = n;
for(int i = 0; i < n; ++i){
int idx;
if(v[i].second >= start)
idx = v[i].second + 1 - start;
else
idx = n + v[i].second + 1 - start;
if(v[i].first > n){
replacementSeq[cnt_replacement++] = idx;
++new_n;
while(v[i].first != new_n){
replacementSeq[cnt_replacement++] = new_n;
++new_n;
}
}
}
return cnt_replacement;
}
const long long mod = 1e9 + 9;
long long fpow(long long base, long long exp){
if(!exp)
return 1;
if(exp & 1)
return fpow(base, exp ^ 1) * base % mod;
long long t = fpow(base, exp >> 1);
return t * t % mod;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq))
return 0;
int start = 0;
bool start_exists = false;
for(int i = 0; i < n; ++i){
if(inputSeq[i] <= n){
start = i + 1 - inputSeq[i];
if(start < 0)
start += n;
start_exists = true;
break;
}
}
int cnt_changed = 0;
for(int i = 0; i < n; ++i)
if(inputSeq[i] > n)
++cnt_changed;
vector<pair<int, int>> v(n);
for(int i = 0; i < n; ++i)
v[i] = {inputSeq[i], i};
sort(v.begin(), v.end());
int new_n = n;
long long ans = 1;
for(int i = 0; i < n; ++i){
if(v[i].first > n){
ans *= fpow(cnt_changed, v[i].first - new_n - 1);
ans %= mod;
new_n = v[i].first;
--cnt_changed;
}
}
if(!start_exists){
ans *= n;
ans %= mod;
}
return ans;
}
# |
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 |
256 KB |
Output is correct |
4 |
Correct |
5 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 |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
504 KB |
Output is correct |
7 |
Correct |
17 ms |
632 KB |
Output is correct |
8 |
Correct |
18 ms |
632 KB |
Output is correct |
9 |
Correct |
10 ms |
376 KB |
Output is correct |
10 |
Correct |
26 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
14 ms |
504 KB |
Output is correct |
7 |
Correct |
17 ms |
632 KB |
Output is correct |
8 |
Correct |
18 ms |
632 KB |
Output is correct |
9 |
Correct |
10 ms |
380 KB |
Output is correct |
10 |
Correct |
23 ms |
632 KB |
Output is correct |
11 |
Correct |
6 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 |
17 ms |
636 KB |
Output is correct |
# |
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 |
256 KB |
Output is correct |
4 |
Correct |
4 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 |
376 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 |
352 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 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 |
5 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 |
18 ms |
1272 KB |
Output is correct |
12 |
Correct |
20 ms |
1400 KB |
Output is correct |
13 |
Correct |
20 ms |
1116 KB |
Output is correct |
14 |
Correct |
18 ms |
1276 KB |
Output is correct |
15 |
Correct |
26 ms |
2152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 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 |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
428 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
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 |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 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 |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
24 ms |
1144 KB |
Output is correct |
10 |
Correct |
24 ms |
1016 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
12 ms |
604 KB |
Output is correct |
13 |
Correct |
6 ms |
376 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 |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 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 |
27 ms |
1144 KB |
Output is correct |
10 |
Correct |
21 ms |
1016 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
14 ms |
632 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
30 ms |
1272 KB |
Output is correct |
15 |
Correct |
33 ms |
1528 KB |
Output is correct |
16 |
Correct |
9 ms |
504 KB |
Output is correct |
17 |
Correct |
24 ms |
1144 KB |
Output is correct |
18 |
Correct |
15 ms |
760 KB |
Output is correct |