#include "gondola.h"
#include <iostream>
#include <vector>
#include <cassert>
#include <set>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000009
int A[100000], cur[100000];
int cnt[250000];
bool glock;
int valid(int N, int inputSeq[]) {
rep(i, 250000) cnt[i] = 0;
rep(i, N) A[i] = inputSeq[i]-1;
rep(i, N) cnt[A[i]]++;
rep(i, 250000) if (cnt[i] > 1) return 0;
int base = -1;
rep(i, N) if (A[i] < N) base = (A[i]-i+N)%N;
rep(i, N) cur[i] = (i+max(0,base))%N;
glock = false;
if (base == -1) return 1;
glock = true;
rep(i, N) if (A[i] < N && A[i] != cur[i]) return 0;
return 1;
}
//----------------------
int rev[250000];
int replacement(int N, int gondolaSeq[], int replacementSeq[]) {
set<int> unused;
assert(valid(N, gondolaSeq));
rep(i, N) rev[A[i]] = i;
rep(i, N) if (A[i] >= N) unused.insert(i);
int m = *max_element(A, A+N);
int c = 0;
for (int i=N; i<=m; i++) {
int p = -1;
if (cnt[i]) {
p = rev[i];
unused.erase(rev[i]);
}
else p = *unused.begin();
replacementSeq[c++] = cur[p]+1;
cur[p] = i;
}
return c;
}
//----------------------
int countReplacement(int N, int inputSeq[]) {
if (valid(N, inputSeq) == 0) return 0;
int unused = 0;
rep(i, N) if (A[i] >= N) unused++;
int m = *max_element(A, A+N);
int s = 1;
if (!glock) s *= N;
int c = 0;
for (int i=N; i<=m; i++) {
int p = -1;
if (cnt[i]) {
p = rev[i];
unused--;
}
else {
s = (1LL*s*unused)%MOD;
}
}
return s;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:64:9: warning: variable 'p' set but not used [-Wunused-but-set-variable]
int p = -1;
^
gondola.cpp:62:7: warning: unused variable 'c' [-Wunused-variable]
int c = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
6 |
Correct |
7 ms |
6124 KB |
Output is correct |
7 |
Correct |
14 ms |
6124 KB |
Output is correct |
8 |
Correct |
11 ms |
6124 KB |
Output is correct |
9 |
Correct |
4 ms |
6124 KB |
Output is correct |
10 |
Correct |
13 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
6 |
Correct |
6 ms |
6124 KB |
Output is correct |
7 |
Correct |
2 ms |
6124 KB |
Output is correct |
8 |
Correct |
12 ms |
6124 KB |
Output is correct |
9 |
Correct |
4 ms |
6124 KB |
Output is correct |
10 |
Correct |
13 ms |
6124 KB |
Output is correct |
11 |
Correct |
0 ms |
6124 KB |
Output is correct |
12 |
Correct |
1 ms |
6124 KB |
Output is correct |
13 |
Correct |
7 ms |
6124 KB |
Output is correct |
14 |
Correct |
1 ms |
6124 KB |
Output is correct |
15 |
Correct |
15 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
0 ms |
6124 KB |
Output is correct |
3 |
Correct |
0 ms |
6124 KB |
Output is correct |
4 |
Correct |
0 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
6 |
Correct |
1 ms |
6124 KB |
Output is correct |
7 |
Correct |
0 ms |
6124 KB |
Output is correct |
8 |
Correct |
1 ms |
6124 KB |
Output is correct |
9 |
Correct |
1 ms |
6124 KB |
Output is correct |
10 |
Correct |
2 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
0 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
6 |
Correct |
1 ms |
6124 KB |
Output is correct |
7 |
Correct |
1 ms |
6124 KB |
Output is correct |
8 |
Correct |
1 ms |
6124 KB |
Output is correct |
9 |
Correct |
1 ms |
6124 KB |
Output is correct |
10 |
Correct |
2 ms |
6124 KB |
Output is correct |
11 |
Correct |
10 ms |
6124 KB |
Output is correct |
12 |
Correct |
16 ms |
6124 KB |
Output is correct |
13 |
Correct |
23 ms |
7576 KB |
Output is correct |
14 |
Correct |
13 ms |
6124 KB |
Output is correct |
15 |
Correct |
16 ms |
6916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
0 ms |
6124 KB |
Output is correct |
5 |
Correct |
0 ms |
6124 KB |
Output is correct |
6 |
Correct |
0 ms |
6124 KB |
Output is correct |
7 |
Correct |
1 ms |
6124 KB |
Output is correct |
8 |
Correct |
1 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6124 KB |
Output is correct |
2 |
Correct |
0 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
1 ms |
6124 KB |
Output is correct |
6 |
Correct |
1 ms |
6124 KB |
Output is correct |
7 |
Correct |
1 ms |
6124 KB |
Output is correct |
8 |
Correct |
0 ms |
6124 KB |
Output is correct |
9 |
Correct |
14 ms |
6124 KB |
Output is correct |
10 |
Correct |
10 ms |
6124 KB |
Output is correct |
11 |
Correct |
7 ms |
6124 KB |
Output is correct |
12 |
Correct |
7 ms |
6124 KB |
Output is correct |
13 |
Correct |
4 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6124 KB |
Output is correct |
2 |
Correct |
1 ms |
6124 KB |
Output is correct |
3 |
Correct |
1 ms |
6124 KB |
Output is correct |
4 |
Correct |
1 ms |
6124 KB |
Output is correct |
5 |
Correct |
0 ms |
6124 KB |
Output is correct |
6 |
Correct |
1 ms |
6124 KB |
Output is correct |
7 |
Correct |
1 ms |
6124 KB |
Output is correct |
8 |
Correct |
1 ms |
6124 KB |
Output is correct |
9 |
Correct |
12 ms |
6124 KB |
Output is correct |
10 |
Correct |
23 ms |
6124 KB |
Output is correct |
11 |
Correct |
7 ms |
6124 KB |
Output is correct |
12 |
Correct |
6 ms |
6124 KB |
Output is correct |
13 |
Correct |
4 ms |
6124 KB |
Output is correct |
14 |
Runtime error |
12 ms |
6124 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |