Submission #138656

#TimeUsernameProblemLanguageResultExecution timeMemory
138656Mahmoud_AdelGondola (IOI14_gondola)C++14
25 / 100
15 ms4264 KiB
#include "gondola.h" #include <bits/stdc++.h> const int N = 1e6+5; int mark[N], mep[N]; using namespace std; int valid(int n, int inputSeq[]) { for(int i=0; i<n; i++) { if(mark[inputSeq[i]]) return 0; else mark[inputSeq[i]] = 1; } int j = -1; for(int i=0; i<n; i++) if(inputSeq[i] > 0 && inputSeq[i] <= n) j = i; if(j == -1) return 1; for(int i=0; i<n; i++) { int id = (i+j)%n, jd = (i+j+1)%n; if(inputSeq[jd] > n) inputSeq[jd] = inputSeq[id]%n + 1; if(inputSeq[jd] != inputSeq[id]%n + 1) return 0; } return 1; } //---------------------- int replacement(int n, int inputSeq[], int replacementSeq[]) { memset(mep, 0, sizeof mep); int j = -1, c = n; for(int i=0; i<n; i++) if(inputSeq[i] <= n) j = i; if(j == -1) { for(int i=0; i<n; i++) replacementSeq[inputSeq[i]] = i+1; return n; } for(int i=0; i<n; i++) { int id = (i+j) % n, jd = (i+j+1) % n; if(inputSeq[jd] > n) c = max(c, inputSeq[jd]), mep[inputSeq[jd]] = inputSeq[id]%n + 1, inputSeq[jd] = inputSeq[id]%n + 1; } int last = -1; for(int i=c; i>n; i--) { if(mep[i] && last == -1) last = i; if(!mep[i]) replacementSeq[i-n-1] = replacementSeq[last-n-1], replacementSeq[last-n-1] = i; else replacementSeq[i-n-1] = mep[i]; } return c-n; } //---------------------- 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...