Submission #297973

#TimeUsernameProblemLanguageResultExecution timeMemory
297973PlurmGondola (IOI14_gondola)C++11
15 / 100
17 ms768 KiB
#include "gondola.h" #include <cstring> int valid(int n, int inputSeq[]) { int offs = -1; for(int i = 0; i < n; i++){ if(inputSeq[i] == 1) offs = i; } for(int i = 0; i < n; i++){ if(inputSeq[(i+offs) % n] <= n && inputSeq[(i+offs) % n] != i+1) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int offs = 0; int dummy = 0; int mx = -1; int* expect = new int[250005]; memset(expect, -1, sizeof(expect)); for(int i = 0; i < n; i++){ if(gondolaSeq[i] <= n) offs = i-gondolaSeq[i]+1; else expect[gondolaSeq[i]] = i; if(gondolaSeq[i] > mx){ mx = gondolaSeq[i]; dummy = i; } } int rpidx = 0; for(int i = n+1; i <= mx; i++){ if(expect[i] == -1){ replacementSeq[rpidx++] = gondolaSeq[dummy]; gondolaSeq[dummy] = i; }else{ replacementSeq[rpidx++] = gondolaSeq[expect[i]]; gondolaSeq[expect[i]] = i; } } return rpidx; } //---------------------- int countReplacement(int n, int inputSeq[]) { if(!valid(n, inputSeq)) return 0; else return 1; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:23:21: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
   23 |  memset(expect, -1, sizeof(expect));
      |                     ^~~~~~~~~~~~~~
gondola.cpp:19:6: warning: variable 'offs' set but not used [-Wunused-but-set-variable]
   19 |  int offs = 0;
      |      ^~~~
#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...