Submission #656847

#TimeUsernameProblemLanguageResultExecution timeMemory
656847happypotatoGondola (IOI14_gondola)C++17
100 / 100
35 ms5004 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; int valid(int n, int inputSeq[]) { int seq[n]; set<int> s; for (int i = 0; i < n; i++) { seq[i] = (inputSeq[i] <= n ? inputSeq[i] : -1); if (s.find(inputSeq[i]) != s.end()) return 0; s.insert(inputSeq[i]); } int samemod = -1; for (int i = 0; i < n; i++) { if (seq[i] == -1) continue; int curmod = (seq[i] + n - i) % n; if (samemod == -1) samemod = curmod; else if (samemod != curmod) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector<pair<int, int>> v; v.push_back({n, -1}); int samemod = 0; for (int i = 0; i < n; i++) { if (gondolaSeq[i] <= n) { samemod = (gondolaSeq[i] + n - i) % n; } else { v.push_back({gondolaSeq[i], i}); } } sort(v.begin(), v.end()); int ptr = 0; for (int i = 1; i < int(v.size()); i++) { int ori = (v[i].second + samemod) % n; if (ori == 0) ori = n; replacementSeq[ptr++] = ori; for (int j = v[i - 1].first + 2; j <= v[i].first; j++) { replacementSeq[ptr++] = j - 1; } } return ptr; } //---------------------- const long long MOD = 1e9 + 9; long long bigmod(long long b, int p) { long long ans = 1; while (p) { if (p & 1) ans = (ans * b) % MOD; p >>= 1; b = (b * b) % MOD; } return ans; } int countReplacement(int n, int inputSeq[]) { vector<int> v; v.push_back(n); int samemod = 0; for (int i = 0; i < n; i++) { if (inputSeq[i] > n) { v.push_back(inputSeq[i]); } } sort(v.begin(), v.end()); int m = v.size(); long long ans = (m == n + 1 ? n : 1); for (int i = 1; i < m; i++) { ans = (ans * bigmod(m - i, (v[i] - v[i - 1] - 1))) % MOD; } return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:66:6: warning: unused variable 'samemod' [-Wunused-variable]
   66 |  int samemod = 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...