Submission #918320

#TimeUsernameProblemLanguageResultExecution timeMemory
918320contest_altGondola (IOI14_gondola)C++17
55 / 100
18 ms2388 KiB
#include "gondola.h" #include <algorithm> #include <vector> int valid( int n, int inputSeq[] ) { int shift_min = n, shift_max = -1; std::vector<int> vals( n ); for( int i = 0 ; i < n ; i++ ){ if( inputSeq[i] > n ) continue; if( inputSeq[i] <= 0 ) return false; vals[i] = inputSeq[i]; int shift = (inputSeq[i] - 1 + n - i) % n; shift_min = std::min( shift_min, shift ); shift_max = std::max( shift_max, shift ); } std::sort( vals.begin(), vals.end() ); for( int i = 1 ; i < n ; i++ ) if( vals[i - 1] == vals[i] ) return false; if( shift_max < 0 ) return true; return shift_min == shift_max; } //---------------------- int replacement( int n, int gondolaSeq[], int replacementSeq[] ) { std::vector<int> base( n ); bool has_base = false; std::vector<std::pair<int, int>> repl; for( int i = 0 ; i < n ; i++ ){ int x = gondolaSeq[i]; if( !has_base && x <= n ){ has_base = true; for( int j = 0 ; j < n ; j++ ) base[(i + j) % n] = (x - 1 + j) % n + 1; } if( x > n ) repl.emplace_back( x, i ); } if( !has_base ) for( int i = 0 ; i < n ; i++ ) base[i] = i + 1; std::sort( repl.begin(), repl.end() ); int len = 0, last = n; for( auto p : repl ){ // o nu... nu am c++17 in 2014 int idx = p.second; int val = p.first; while( base[idx] != val ){ replacementSeq[len++] = base[idx]; base[idx] = ++last; } } return len; } //---------------------- 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...