#include <bits/stdc++.h>
using namespace std;
#include "gondola.h"
#define int long long
const int mod = 1e9+9;
signed valid(signed n, signed S[]){
set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
int ind = -1;
for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
if (ind == -1) return 1;
int t = S[ind];
for (int i=ind+1; i!=ind; i++, i%=n){
t++; if (t==n+1) t = 1;
if (S[i] <= n && S[i] != t) return 0;
}
return 1;
}
signed replacement(signed n, signed S[], signed replacementSeq[]){
int ind = -1;
for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
int bg = -1; map<int,int> tr;
if (ind == -1){
for (int i=0; i<n; i++){
tr[S[i]] = i+1; bg= max(bg,(int)S[i]);
}
} else {
int t = S[ind];
for (int i=(ind+1)%n; i!=ind; i++, i%=n){
t++; if (t==n+1) t = 1;
if (S[i] > n) {tr[S[i]] = t; bg=max(bg,(int)S[i]);}
}
}
if (bg==-1) return 0;
int bgm = tr[bg];
tr.erase(bg);
for (int i=n+1; i<=bg; i++){
if (tr.count(i)){
replacementSeq[i-(n+1)] = tr[i];
} else {
replacementSeq[i-(n+1)] = bgm;
bgm = i;
}
}
return (bg-(n+1) + 1);
}
signed countReplacement(signed n, signed S[]){
if (!valid(n,S)) return 0;
int res = 1;
set<int>tr; for (int i=0; i<n; i++) tr.insert(S[i]);
int bigger = 0;
for (int x: tr) if (x>=n+1) bigger++;
if (!bigger) return 1;
if (bigger == n) res *= n;
for (int i=n+1; i < 25e4+6; i++){
if (tr.count(i)){
bigger--; if (!bigger) return res;
} else {
res *= bigger; res %= mod;
}
}
return res;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:9:65: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
9 | set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
| ~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2396 KB |
Output is correct |
7 |
Correct |
20 ms |
4120 KB |
Output is correct |
8 |
Correct |
17 ms |
4440 KB |
Output is correct |
9 |
Correct |
5 ms |
1628 KB |
Output is correct |
10 |
Correct |
19 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
2396 KB |
Output is correct |
7 |
Correct |
19 ms |
4312 KB |
Output is correct |
8 |
Correct |
15 ms |
4440 KB |
Output is correct |
9 |
Correct |
5 ms |
1624 KB |
Output is correct |
10 |
Correct |
19 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
24 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
428 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1088 KB |
Output is correct |
12 |
Correct |
8 ms |
1112 KB |
Output is correct |
13 |
Correct |
19 ms |
3272 KB |
Output is correct |
14 |
Correct |
6 ms |
1116 KB |
Output is correct |
15 |
Correct |
30 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
440 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
436 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
41 ms |
4424 KB |
Output is correct |
10 |
Correct |
33 ms |
3936 KB |
Output is correct |
11 |
Correct |
16 ms |
1628 KB |
Output is correct |
12 |
Correct |
15 ms |
2012 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
376 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
42 ms |
4516 KB |
Output is correct |
10 |
Correct |
37 ms |
3920 KB |
Output is correct |
11 |
Correct |
14 ms |
1628 KB |
Output is correct |
12 |
Correct |
15 ms |
1884 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Incorrect |
46 ms |
5504 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |