Submission #445587

#TimeUsernameProblemLanguageResultExecution timeMemory
445587AlexRex0Gondola (IOI14_gondola)C++14
60 / 100
47 ms4588 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...