Submission #355612

#TimeUsernameProblemLanguageResultExecution timeMemory
355612MefarnisGondola (IOI14_gondola)C++14
20 / 100
48 ms5100 KiB
#include <bits/stdc++.h> #include "gondola.h" #define maxn 100003 #define maxv 250001 using namespace std; int idx[maxn]; int init[maxn]; void calcInit(int n, int inputSeq[], int minIdx) { if(minIdx == -1) for( int i = 0 ; i < n ; i++ ) init[i] = i+1; else for( int i = 0 ; i < n ; i++ ) { int d = (i-minIdx+n) % n; init[i] = inputSeq[minIdx]+d; } } int valid(int n, int inputSeq[]) { int minIdx = -1; set<int> s; for( int i = 0 ; i < n ; i++ ) { if(s.find(inputSeq[i]) != s.end()) return 0; s.insert(inputSeq[i]); if(inputSeq[i] <= n) { if(minIdx == -1 || inputSeq[i] < inputSeq[minIdx]) minIdx = i; } } calcInit(n,inputSeq,minIdx); if(minIdx == -1) return 1; for( int i = 0 ; i < n ; i++ ) if(inputSeq[i] <= n) { if(init[i] != inputSeq[i]) return 0; } return 1; } int replacement(int n, int inputSeq[], int replacementSeq[]) { if(!valid(n,inputSeq)) return 0; int maxIdx = -1; memset(idx,-1,sizeof(idx)); for( int i = 0 ; i < n ; i++ ) { idx[inputSeq[i]] = i; if(maxIdx == -1 || inputSeq[i] > inputSeq[maxIdx]) maxIdx = i; } int cnt = 0; int curr = init[maxIdx]; int maxVal = inputSeq[maxIdx]; for( int i = n+1 ; i <= maxVal ; i++ ) { if(idx[i] == -1 || i == maxVal) replacementSeq[cnt++] = curr++; else replacementSeq[cnt++] = init[idx[i]]; } return cnt; } int countReplacement(int n, int inputSeq[]) { if(!valid(n,inputSeq)) return 0; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
   69 | }
      | ^
#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...