Submission #391917

#TimeUsernameProblemLanguageResultExecution timeMemory
391917Aldas25Gondola (IOI14_gondola)C++14
60 / 100
24 ms4280 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<int> vi; int valid(int n, int inputSeq[]) { FOR(i, 0, n-1) inputSeq[i]--; unordered_set<int> cont; FOR(i, 0, n-1) cont.insert(inputSeq[i]); if ((int)cont.size() < n) return false; int ch = -1; FOR(i, 0, n-1) { if (inputSeq[i] >= n) continue; ch = i; break; } if (ch == -1) return true; FOR(i, 0, n-1) { int id = (ch+i)%n; if (inputSeq[id] >= n) continue; int shouldBe = (inputSeq[ch]+i)%n; if (inputSeq[id] != shouldBe) return false; } return true; } //---------------------- int replacement(int n, int inputSeq[], int replacementSeq[]) { FOR(i, 0, n-1) inputSeq[i]--; int l = 0; int ch = 0; FOR(i, 0, n-1) { if (inputSeq[i] >= n) continue; ch = i; break; } int cur[n]; cur[ch] = (inputSeq[ch] < n ? inputSeq[ch] : 0); FOR(i, 0, n-1) { int id = (ch+i)%n; int shouldBe = (cur[ch]+i)%n; cur[id] = shouldBe; } vii seq; FOR(i, 0, n-1) { seq.pb({inputSeq[i], i}); } sort(seq.begin(), seq.end()); int crAdd = n; for (auto p : seq) { int id = p.s; while (cur[id] < inputSeq[id]) { replacementSeq[l] = cur[id]+1; cur[id] = crAdd; crAdd++; l++; } } return l; } //---------------------- const ll MOD = 1e9+7; ll pwr (ll a, ll p) { if (p == 0) return 1ll; if (p == 1) return a%MOD; ll ret = pwr(a, p/2); ret = (ret*ret)%MOD; if (p%2 == 1) ret *= a%MOD; return ret%MOD; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; ll ans = 1; FOR(i, 0, n-1) inputSeq[i]--; int ch = 0; FOR(i, 0, n-1) { if (inputSeq[i] >= n) continue; ch = i; break; } vii seq; FOR(i, 0, n-1) { seq.pb({inputSeq[i], i}); } sort(seq.begin(), seq.end()); ll rem = n; ll lst = n-1; for (auto p : seq) { int id = p.s; if (inputSeq[id] >= n) { ll cnt = inputSeq[id] - lst + 1; ll cr = pwr(rem, cnt); ans = (ans*cr)%MOD; lst = inputSeq[id]; } rem--; } return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:111:9: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
  111 |     int ch = 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...