Submission #169409

#TimeUsernameProblemLanguageResultExecution timeMemory
169409AlexLuchianovGondola (IOI14_gondola)C++14
100 / 100
83 ms6776 KiB
#include "gondola.h" #include <algorithm> #include <iostream> #include <map> #include <vector> using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 250000; int const modulo = 1000000009; std::map<int, int> frec; int valid(int n, int inputSeq[]) { for(int i = 0; i < n; i++) if(inputSeq[i] <= n) { std::rotate(inputSeq, inputSeq + (n + i - inputSeq[i] + 1) % n, inputSeq + n); break; } for(int i = 0; i < n; i++) { if(frec[inputSeq[i]] == 1) return false; frec[inputSeq[i]] = 1; if(inputSeq[i] <= n && i + 1 != inputSeq[i]) return false; } return true; } //---------------------- int seen[1 + nmax]; int replacement(int n, int gondolaSeq[], int replacementSeq[]) { for(int i = 0; i < n; i++) if(gondolaSeq[i] <= n) { std::rotate(gondolaSeq, gondolaSeq + (n + i - gondolaSeq[i] + 1) % n, gondolaSeq + n); break; } int smax = 0; for(int i = 0; i < n; i++) smax = MAX(smax, gondolaSeq[i]); int pos = 0; for(int i = 0; i < n; i++) if(smax == gondolaSeq[i]) pos = i + 1; for(int i = 0;i < n; i++) seen[gondolaSeq[i]] = 1 + i; for(int i = n + 1; i <= smax; i++) if(seen[i] == 0 || i == smax) { replacementSeq[i - n - 1] = pos; pos = i; } else replacementSeq[i - n - 1] = seen[i]; return smax - n; } //---------------------- int lgpow(int a, int b){ if(b == 0) return 1; else if(b == 1) return a; else { int result = lgpow(a, b / 2); if(b % 2 == 0) return 1LL * result * result % modulo; else return 1LL * result * result % modulo * a % modulo; } } int countReplacement(int n, int inputSeq[]) { if(valid(n, inputSeq) == 0) return 0; else { int centered = 0; for(int i = 0; i < n; i++) if(inputSeq[i] <= n) { std::rotate(inputSeq, inputSeq + (n + i - inputSeq[i] + 1) % n, inputSeq + n); centered = 1; break; } std::vector<int> v; for(int i = 0; i < n; i++) if(n < inputSeq[i] ) v.push_back(inputSeq[i]); std::sort(v.begin(), v.end()); int last = n; int result = 1; for(int i = 0; i < v.size(); i++){ result = 1LL * result * lgpow(v.size() - i, v[i] - 1 - last) % modulo; last = v[i]; } if(centered == 0) return 1LL * n * result % modulo; else return result; } }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:104:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++){
                    ~~^~~~~~~~~~
#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...