Submission #441269

#TimeUsernameProblemLanguageResultExecution timeMemory
441269AlexRex0Gondola (IOI14_gondola)C++14
25 / 100
40 ms4592 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; } //---------------------- int countReplacement(int n, int inputSeq[]) { return -3; }
#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...