Submission #586306

#TimeUsernameProblemLanguageResultExecution timeMemory
586306SeDunionGondola (IOI14_gondola)C++17
100 / 100
32 ms9364 KiB
#include "gondola.h" #include<iostream> #include<algorithm> using namespace std; const int N = 1e6 + 123; int u[N]; int valid(int n, int inputSeq[]) { int id = -1; for (int i = 0 ; i < n ; ++ i) { if (inputSeq[i] <= n) id = i; } for (int i = 0 ; i < n ; ++ i) u[i] = inputSeq[i]; sort(u, u + n); for (int i = 1 ; i < n ; ++ i) if (u[i] == u[i - 1]) return 0; if (id == -1) return 1; int x = inputSeq[id]; for (int i = 0 ; i + x <= n ; ++ i) { int j = (i + id) % n; if (inputSeq[j] != i + x && inputSeq[j] <= n) return 0; } for (int i = 0 ; i < x ; ++ i) { int j = (id - i + n) % n; if (inputSeq[j] != x - i && inputSeq[j] <= n) return 0; } return 1; } //---------------------- pair<int,int>pp[N]; int tt[N]; int replacement(int n, int gondolaSeq[], int replacementSeq[]) { for (int i = 0 ; i < n ; ++ i) { pp[i] = {gondolaSeq[i], i}; } sort(pp, pp + n); int id = 0, x = 1; if (pp[0].first <= n) id = pp[0].second, x = pp[0].first; for (int i = 0 ; i + x <= n ; ++ i) { int j = (i + id) % n; tt[j] = i + x; } for (int i = 1 ; i < x ; ++ i) { int j = (id - i + n) % n; tt[j] = x - i; } int m = 0; int t = n; for (int i = 0 ; i < n ; ++ i) { int x = pp[i].first; int y = pp[i].second; if (x <= n) continue; while (tt[y] < x) { replacementSeq[m++] = tt[y]; tt[y] = ++t; } } return m; } //---------------------- const int mod = 1e9 + 9; using ll = long long; ll binpow(ll a, ll b) { ll r = 1; while (b) { if (b & 1) r = r * a % mod; b >>= 1; a = a * a % mod; } return r; } ll fact[N]; int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) { return 0; } for (int i = 0 ; i < n ; ++ i) { u[i] = inputSeq[i]; } sort(u, u + n); int t = n; ll ans = 1; if (u[0] > n) { fact[0] = 1; for (int i = 1 ; i < N ; ++ i) fact[i] = fact[i - 1] * i % mod; ans = n; } for (int i = 0 ; i < n ; ++ i) { int x = u[i]; if (x <= n) continue; long long z = x - t - 1; ans *= binpow(n - i, z) % mod; ans %= mod; t = x; } 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...