#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
set<int> existe;
int valid(int n, int inputSeq[])
{
int valido = 1, inicio = -1, valor = INT_MAX;
for(int i = 0; i < n; ++i){
if(inputSeq[i] <= n && inputSeq[i] < valor){
inicio = i;
valor = inputSeq[i];
}
if(existe.count(inputSeq[i]) != 0){
valido = 0;
}
existe.insert(inputSeq[i]);
}
if(inicio != -1){
valor++;
for(int i = inicio + 1; i < n; ++i){
if(inputSeq[i] <= n && inputSeq[i] != valor){
valido = 0;
}
valor++;
}
for(int i = 0; i < inicio; ++i){
if(inputSeq[i] <= n && inputSeq[i] != valor){
valido = 0;
}
valor++;
}
}
return valido;
}
//----------------------
struct dato{
int original, valor;
};
dato arre[100002];
bool compara(dato a, dato b){
if(a.valor < b.valor){
return true;
}
return false;
}
set<int> ocupe;
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int ind = 0, cont = 0, ini = -1, mayor = INT_MAX;
for(int i = 0; i < n; ++i){
if(gondolaSeq[i] <= n && gondolaSeq[i] < mayor){
mayor = gondolaSeq[i];
ini = i;
}
ocupe.insert(gondolaSeq[i]);
}
if(ini != -1){
for(int i = ini; i < n; ++i){
arre[i].original = mayor;
ocupe.insert(mayor);
arre[i].valor = gondolaSeq[i];
mayor++;
}
for(int i = 0; i < ini; ++i){
arre[i].original = mayor;
ocupe.insert(mayor);
arre[i].valor = gondolaSeq[i];
mayor++;
}
mayor = gondolaSeq[ini] - 1;
for(int i = ini - 1; i >= 0; --i){
if(mayor > 0){
arre[i].original = mayor;
ocupe.insert(mayor);
}
mayor--;
}
}else{
mayor = 1;
for(int i = 0; i < n; ++i){
arre[i].original = mayor;
ocupe.insert(mayor);
arre[i].valor = gondolaSeq[i];
mayor++;
}
}
sort(arre, arre + n, compara);
for(int i = 0; i < n; ++i){
while(arre[i].original < arre[i].valor){
replacementSeq[ind] = arre[i].original;
ind++;
cont++;
while(arre[i].original < arre[i].valor && ocupe.count(arre[i].original) == 1){
arre[i].original++;
}
}
}
return cont;
}
//----------------------
bool fijo[250002];
long long int acumulado[250002];
long long int original[250002];
long long int aux, pos = -1, res = 1, suma;
int countReplacement(int n, int inputSeq[])
{
for(int i = 0; i < n; ++i){
if(inputSeq[i] <= n){
aux = inputSeq[i];
pos = i;
break;
}
}
if(pos == -1){
aux = 1;
for(int i = 0; i < n; ++i){
original[i] = aux;
aux++;
}
res*= n;
res%= 1000000009;
}else{
while(aux > 1){
aux--;
pos--;
if(pos == -1){
pos = n - 1;
}
}
for(int i = pos; i < n; ++i){
original[i] = aux;
aux++;
}
for(int i = 0; i < pos; ++i){
original[i] = aux;
aux++;
}
}
for(int i = 0; i < n; ++i){
fijo[inputSeq[i]] = true;
fijo[original[i]] = true;
acumulado[original[i]]++;
acumulado[inputSeq[i] + 1]--;
}
for(int i = 1; i <= 250000; ++i){
suma+= acumulado[i];
if(!fijo[i]){
if(suma > 0){
res*= suma;
}
res%= 1000000009;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
2124 KB |
Output is correct |
7 |
Correct |
47 ms |
3652 KB |
Output is correct |
8 |
Correct |
38 ms |
3904 KB |
Output is correct |
9 |
Correct |
8 ms |
1484 KB |
Output is correct |
10 |
Correct |
35 ms |
4420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
17 ms |
2180 KB |
Output is correct |
7 |
Correct |
35 ms |
3628 KB |
Output is correct |
8 |
Correct |
29 ms |
3900 KB |
Output is correct |
9 |
Correct |
8 ms |
1356 KB |
Output is correct |
10 |
Correct |
35 ms |
4440 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
16 ms |
2048 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
43 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 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 |
Runtime error |
5 ms |
3152 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
5 ms |
3148 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
12 ms |
2820 KB |
Output is correct |
10 |
Correct |
10 ms |
2176 KB |
Output is correct |
11 |
Correct |
5 ms |
2124 KB |
Output is correct |
12 |
Correct |
6 ms |
1740 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
12 ms |
2764 KB |
Output is correct |
10 |
Correct |
10 ms |
2124 KB |
Output is correct |
11 |
Correct |
7 ms |
2124 KB |
Output is correct |
12 |
Correct |
6 ms |
1740 KB |
Output is correct |
13 |
Correct |
3 ms |
844 KB |
Output is correct |
14 |
Runtime error |
14 ms |
2328 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |