Submission #995414

#TimeUsernameProblemLanguageResultExecution timeMemory
995414thinknoexitGondola (IOI14_gondola)C++17
55 / 100
13 ms2388 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 9; bool ch[250500]; int p[100100]; int valid(int n, int a[]) { int mn = n + 1; int idx = 0; for (int i = 0;i < n;i++) { if (ch[a[i]]) return 0; ch[a[i]] = 1; if (a[i] <= n) { if (a[i] < mn) { mn = a[i]; idx = i; } } } if (mn == n + 1) return 1; idx = (idx - mn + 1 + n) % n; for (int i = 0;i < n;i++) { if (a[(i + idx) % n] <= n && a[(i + idx) % n] != i + 1) return 0; } return 1; } int replacement(int n, int a[], int replacementSeq[]) { int mn = n + 1; int idx = 0; vector<pair<int, int>> v; for (int i = 0;i < n;i++) { if (a[i] <= n) { if (a[i] < mn) { mn = a[i]; idx = i; } } else v.push_back({ a[i], i }); } idx = (idx - mn + 1 + n) % n; for (int i = 0;i < n;i++) { p[(i + idx) % n] = i + 1; } int sz = 0, now = n; sort(v.begin(), v.end()); for (auto& x : v) { while (p[x.second] != x.first) { replacementSeq[sz++] = p[x.second]; p[x.second] = ++now; } } return sz; } int countReplacement(int n, int a[]) { if (!valid(n, a)) return 0; memset(ch, 0, sizeof ch); int cnt = 0; for (int i = 0;i < n;i++) { if (a[i] > n) cnt++; } ll ans = 1; for (int i = n + 1;i <= 250000;i++) { if (cnt == 0) break; if (!ch[i]) { ans = (ans * cnt) % MOD; } else cnt--; } return ans; }
#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...