Submission #362513

#TimeUsernameProblemLanguageResultExecution timeMemory
362513PetyGondola (IOI14_gondola)C++14
100 / 100
58 ms5100 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; const int mod = 1e9 + 9; long long logpow (long long a, long long b) { long long p = 1; while (b) { if (b & 1) p = 1ll * p * a % mod; a = 1ll * a * a % mod; (b >>= 1); } return p; } int valid (int n, int inputSeq[]) { vector<int>f; int poz = 0; for (int i = 0; i < n; i++) { int next = (i + 1) % n; if (inputSeq[i] <= n) { poz = i; } if (inputSeq[i] <= n && inputSeq[next] <= n) { if (inputSeq[i] == n && inputSeq[next] != 1) return 0; else if (inputSeq[i] < n && inputSeq[next] != inputSeq[i] + 1) return 0; } } int val = inputSeq[poz]; for (int i = 1; i <= n; i++) { if (inputSeq[poz] != val && inputSeq[poz] <= n) return 0; val = (val + 1) % n; if (!val) val = n; poz = (poz + 1) % n; } sort(inputSeq, inputSeq + n); for (int i = 0; i < n - 1; i++) if (inputSeq[i] == inputSeq[i + 1]) return 0; return 1; } int replacement (int n, int inputSeq[], int replacementSeq[]) { vector<int>f, pozFinal, poz; f.resize(250002); pozFinal.resize(250002); poz.resize(250002); int mx = 0; int start = 0; for (int i = 0; i < n; i++) { f[inputSeq[i]] = 1; if (inputSeq[i] <= n) start = (i - inputSeq[i] + 1 + n) % n; pozFinal[inputSeq[i]] = i; mx = max(mx, inputSeq[i]); } set<int>s; for (int i = 1; i <= n; i++) { inputSeq[start] = i; poz[i] = start; start = (start + 1) % n; if (!f[i]) s.insert(i); } int l = 0; int next = n + 1; for (int i = 1; i <= mx - n; i++) { if (f[next]) { replacementSeq[i - 1] = inputSeq[pozFinal[next]]; s.erase(replacementSeq[i - 1]); } else { replacementSeq[i - 1] = *s.begin(); s.erase(replacementSeq[i - 1]); s.insert(next); inputSeq[poz[replacementSeq[i - 1]]] = next; poz[next] = poz[replacementSeq[i - 1]]; } next++; } return mx - n; } int countReplacement (int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; int mx = 0; bool meh = 0; vector<int> fixat; int saiz = n; for (int i = 0; i < n; i++) { if (inputSeq[i] <= n) { meh = 1; saiz--; } else fixat.push_back(inputSeq[i]); } sort(fixat.begin(), fixat.end()); long long ans = 1; int last = n + 1; for (int i = 0; i < fixat.size(); i++) { ans = 1ll * ans * logpow(saiz, fixat[i] - last) % mod; saiz--; last = fixat[i] + 1; } return ((meh == 0) ? n : 1) * ans % mod; } /*int main () { int aux[] = {3, 4}; cout << countReplacement(2, aux); return 0; }*/

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:71:7: warning: unused variable 'l' [-Wunused-variable]
   71 |   int l = 0;
      |       ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |   for (int i = 0; i < fixat.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
gondola.cpp:93:7: warning: unused variable 'mx' [-Wunused-variable]
   93 |   int mx = 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...