Submission #792317

#TimeUsernameProblemLanguageResultExecution timeMemory
792317MODDIGondola (IOI14_gondola)C++17
25 / 100
7 ms1108 KiB
#include "gondola.h" //#include "grader.cpp" #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<ll> vl; int valid(int n, int inputSeq[]) { int pos = -1; for(int i = 0; i < n; i++){ if(inputSeq[i] == 1){ pos = i; break; } } bool seq = true; int at = 1, lim = pos; while(pos < n){ if(inputSeq[pos] == at){ pos++; at++; } else{ seq = false; break; } } if(!seq) return 0; pos = 0; while(pos < lim){ if(inputSeq[pos] == at){ pos++; at++; } else{ seq = false; break; } } if(!seq) return 0; return 1; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int pos = -1; for(int i = 0; i < n; i++){ if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n){ pos = i; break; } } if(pos == -1){ vi arr(n); for(int i = 0; i < n; i++) arr[i] = gondolaSeq[i]; sort(arr.begin(), arr.end()); int at = 1, j = 0, rez =0; for(int i = 0; i < n; i++){ while(at < arr[i]){ replacementSeq[j++] = at++; rez++; } at++; } return rez; } else{ int j = 0, rez = 0; int at = gondolaSeq[pos]; while(at <= n){ at++; pos++; pos %= n; } map<int, bool> vis; map<int,int> replace; int need = 1; for(int i = pos; i < n; i++){ vis[gondolaSeq[i]] = true; replace[gondolaSeq[i]] = need++; //cout<<"REPLACE: "<<gondolaSeq[i]<<" "<<need-1<<endl; } for(int i = 0; i < pos; i++){ vis[gondolaSeq[i]] = true; replace[gondolaSeq[i]] = need++; //cout<<"REPLACE: "<<gondolaSeq[i]<<" "<<need-1<<endl; } at = n + 1; bool done[n+1]; memset(done, false, sizeof done); need = 1; //cout<<"STARTING: "<<pos<<" "<<vis[at]<<" "<<at<<" "<<replace[at]<<endl; for(int i = pos; i < n; i++){ //cout<<i<<" "<<at<<" "<<gondolaSeq[i]<<endl; while(at < gondolaSeq[i]){ if(vis[at]){ replacementSeq[j++] = replace[at]; done[replace[at++]] = true; rez++; } else{ if(!done[need]){ done[need] = true; replacementSeq[j++]=need; rez++; } replacementSeq[j++] = at++; rez++; } } need++; if(at == gondolaSeq[i]) { if(!done[replace[gondolaSeq[i]]]){ done[replace[gondolaSeq[i]]] = true; replacementSeq[j++] = replace[gondolaSeq[i]]; rez++; } at++; } } for(int i = 0; i < pos; i++){ while(at < gondolaSeq[i]){ if(vis[at]){ replacementSeq[j++] = replace[at]; done[replace[at++]] = true; rez++; } else{ if(!done[need]){ done[need] = true; replacementSeq[j++]=need; rez++; } replacementSeq[j++] = at++; rez++; } } need++; if(at == gondolaSeq[i]) { if(!done[replace[gondolaSeq[i]]]){ done[replace[gondolaSeq[i]]] = true; replacementSeq[j++] = replace[gondolaSeq[i]]; rez++; } at++; } } //cout<<"ANS: "<<endl; return rez; } } //---------------------- 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...