# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
332274 |
2020-12-01T20:29:16 Z |
zggf |
Gondola (IOI14_gondola) |
C++14 |
|
45 ms |
6280 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
long long offset = -1;
unordered_map<int, bool> odw;
for(long long i = 0; i < n; i++){
if(odw[inputSeq[i]]) return 0;
odw[inputSeq[i]] = true;
if(inputSeq[i]<=n){
long long tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
long long offset = -1;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q;
for(long long i = 0; i < n; i++){
if(gondolaSeq[i]<=n){
long long tmp = (n+gondolaSeq[i]-i-1)%n;
if(offset==-1) offset = tmp;
}else{
q.push(make_pair(gondolaSeq[i], i));
}
}
if(offset==-1) offset=0;
for(long long i = 0; i < n; i++){
gondolaSeq[i] = 1+(i+offset)%n;
}
long long cur = n+1;
for(long long i = 0; !q.empty(); i++){
if(gondolaSeq[q.top().second] < q.top().first){
replacementSeq[i] = gondolaSeq[q.top().second];
gondolaSeq[q.top().second] = cur;
cur++;
}else{
q.pop();
i--;
}
}
return cur-n-1;
return -2;
}
//----------------------
long long mod = 1e9+9;
long long pot(long long a, long long b){
if(b==0) return 1;
if(b%2==0){
long long cur = pot(a, b/2);
return (cur*cur)%mod;
}else return (a*pot(a, b-1))%mod;
}
int countReplacement(int n, int inputSeq[])
{
vector<long long> tab;
long long offset = -1;
long long wyn = 1;
long long cnt = 0;
unordered_map<int, bool> odw;
for(long long i = 0; i < n; i++){
if(odw[inputSeq[i]]) return 0;
odw[inputSeq[i]] = true;
if(inputSeq[i]<=n){
long long tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}else{
cnt++;
tab.push_back(inputSeq[i]);
}
}
sort(tab.begin(), tab.end());
long long cur = n+1;
for(long long i = 0; i < tab.size(); i++){
wyn*=pot(cnt, tab[i]-cur);
wyn%=mod;
cur=tab[i]+1;
cnt--;
}
if(offset==-1) wyn*=n;
wyn%=mod;
return wyn;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:90:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(long long i = 0; i < tab.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
2168 KB |
Output is correct |
7 |
Correct |
10 ms |
620 KB |
Output is correct |
8 |
Correct |
17 ms |
4088 KB |
Output is correct |
9 |
Correct |
8 ms |
1388 KB |
Output is correct |
10 |
Correct |
19 ms |
4240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
2168 KB |
Output is correct |
7 |
Correct |
11 ms |
620 KB |
Output is correct |
8 |
Correct |
20 ms |
4088 KB |
Output is correct |
9 |
Correct |
6 ms |
1388 KB |
Output is correct |
10 |
Correct |
20 ms |
4260 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
11 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
10 ms |
640 KB |
Output is correct |
12 |
Correct |
11 ms |
620 KB |
Output is correct |
13 |
Correct |
18 ms |
1380 KB |
Output is correct |
14 |
Correct |
12 ms |
748 KB |
Output is correct |
15 |
Correct |
26 ms |
2268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
30 ms |
4464 KB |
Output is correct |
10 |
Correct |
22 ms |
3312 KB |
Output is correct |
11 |
Correct |
9 ms |
1516 KB |
Output is correct |
12 |
Correct |
10 ms |
1772 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
28 ms |
4464 KB |
Output is correct |
10 |
Correct |
22 ms |
3312 KB |
Output is correct |
11 |
Correct |
9 ms |
1516 KB |
Output is correct |
12 |
Correct |
10 ms |
1772 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
45 ms |
5768 KB |
Output is correct |
15 |
Correct |
45 ms |
6280 KB |
Output is correct |
16 |
Correct |
8 ms |
1644 KB |
Output is correct |
17 |
Correct |
30 ms |
5108 KB |
Output is correct |
18 |
Correct |
16 ms |
2808 KB |
Output is correct |