#include "gondola.h"
#include <assert.h>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
bool visited[250003];
int rotos[250003];
bool rangos[250003];
struct dato{
int valor;
int pos;
};
bool operator <(const dato &a, const dato &b){
return a.valor < b.valor;
}
dato gon[250003];
int valid(int n, int inputSeq[])
{
int index = 0, aux, valor = 1;
for (int i = 0; i < n; i++){
aux = inputSeq[i];
if (aux <= n){
index = i;
valor = aux;
break;
}
}
for (int i = index; i < n + index; i++){
if (visited[ inputSeq[i % n] ]) return 0;
visited[ inputSeq[i % n] ] = true;
if (inputSeq[i % n] > n){
valor = (valor % n) + 1;
continue;
}
if (inputSeq[i % n] != valor) return 0;
valor = (valor % n) + 1;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int index = 0, aux, valor = 1, L = 0, g = n + 1;
for (int i = 0; i < n; i++){
aux = gondolaSeq[i];
if (aux <= n){
index = i;
valor = aux;
break;
}
}
int posi = 0;
for (int i = index; i < n + index; i++){
aux = gondolaSeq[i % n];
if (aux > n ){
gon[posi].valor = aux;
gon[posi].pos = valor;
posi++;
}
valor = (valor % n) + 1;
}
sort (gon + 0, gon + posi);
g = n + 1;
for (int i = 0; i < posi; i++){
if (gon[i].valor <= n) continue;
replacementSeq[L] = gon[i].pos;
L++;
while (g < gon[i].valor){
replacementSeq[L] = g;
g++;
L++;
}
g = gon[i].valor + 1;
}
return L;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
long long res = 1, maxi = 0, r = 0;
bool uwu = false;
if (!valid(n, inputSeq)) return 0;
for (int i = 0; i < n; i++){
if (inputSeq[i] > n){
r++;
if (inputSeq[i] > maxi) maxi = inputSeq[i];
rangos[inputSeq[i]] = true;
}
}
if (r == n) uwu = true;
if (r == 0) return 1;
long long int mod = 1000000009;
for (int i = n + 1; i <= maxi; i++){
if (rangos[i]) r--;
else res = res * r % mod;
}
if (uwu) res = res * n % mod;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
10 ms |
628 KB |
Output is correct |
8 |
Correct |
9 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
10 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
10 ms |
608 KB |
Output is correct |
8 |
Correct |
9 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
10 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
5 ms |
440 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
10 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
260 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
576 KB |
Output is correct |
12 |
Correct |
11 ms |
644 KB |
Output is correct |
13 |
Correct |
15 ms |
1340 KB |
Output is correct |
14 |
Correct |
10 ms |
588 KB |
Output is correct |
15 |
Correct |
28 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
11 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
680 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
11 ms |
876 KB |
Output is correct |
10 |
Correct |
9 ms |
744 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
644 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Runtime error |
13 ms |
1072 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |