Submission #603552

#TimeUsernameProblemLanguageResultExecution timeMemory
6035528e7Gondola (IOI14_gondola)C++17
100 / 100
21 ms2216 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r)cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define mod 1000000009 #define pii pair<int, int> #define ff first #define ss second #include "gondola.h" int valid(int n, int a[]) { int ret = 1, st = -1; for (int i = 0;i < n;i++) { if (a[i] > n) continue; int val = (a[i] - i - 1 + n) % n; if (st == -1) st = val; else if (val != st) { ret = 0; break; } } sort(a, a + n); for (int i = 1;i < n;i++) { if (a[i] == a[i-1]) ret = 0; } return ret; } //---------------------- int replacement(int n, int a[], int ret[]) { int cur = n+1, ind = 0, dif = 0; for (int i = 0;i < n;i++) { if (a[i] <= n) dif = (a[i] - i - 1 + n) % n; } vector<pii> v; for (int i = 0;i < n;i++) { if (a[i] > n) { v.push_back({a[i], i}); a[i] = (dif + i)%n + 1; } } sort(v.begin(), v.end()); for (auto [val, id]:v) { while (cur <= val) { ret[ind++] = a[id]; a[id] = cur++; } } return ind; } //---------------------- ll modpow(ll a, ll p) { ll ret = 1; while (p) { if (p & 1) ret = ret * a % mod; a = a * a % mod; p >>= 1; } return ret; } int countReplacement(int n, int a[]) { ll ans = 1; if (valid(n, a) == 0) return 0; int big = 0, cur = n; vector<int> v; for (int i = 0;i < n;i++) { if (a[i] > n) { big++; v.push_back(a[i]); } } if (big == n) ans *= n; sort(v.begin(), v.end()); for (int i:v) { ans = ans * modpow(big, i - cur - 1) % mod; cur = i; big--; } return (int)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...