Submission #1153097

#TimeUsernameProblemLanguageResultExecution timeMemory
1153097vladiliusGondola (IOI14_gondola)C++20
100 / 100
45 ms5444 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second const int mod = 1e9 + 9; int valid(int n, int x[]){ map<int, bool> f; int m = 0; for (int i = 0; i < n; i++){ if (f.find(x[i]) != f.end()) return 0; f[x[i]] = 1; m = max(m, x[i]); } pii mn = {1e9, 0}; for (int i = 0; i < n; i++) mn = min(mn, {x[i], i}); int p = mn.ss; vector<int> y(n); for (int i = 0; i < n; i++){ int j = i - p; if (j < 0) j += n; y[j] = x[i]; } int X = y[0]; for (int i = 1; i < n; i++){ if (y[i] > n) continue; int Y = y[i] - i; if (Y < 0) Y += n; if (Y != X) return 0; } if (m >= 2 * n) return 1; int cc = 0; for (int i = 1; i <= n; i++) cc += f[i]; if ((n - cc) > (m - n)) return 0; return 1; } int replacement(int n, int a[], int b[]){ int m = 0; for (int i = 0; i < n; i++) m = max(m, a[i]); int p = 0; for (int i = 0; i < n; i++){ if (a[i] <= n){ p = i; } } p = (a[p] - p - 1) % n; if (p < 0) p += n; vector<int> x(n); for (int i = 0; i < n; i++){ int j = i + p; if (j >= n) j -= n; x[j] = a[i]; } vector<pii> all; for (int i = 0; i < n; i++){ if (x[i] > n) all.pb({x[i], i}); } vector<int> f(n); for (int i = 0; i < n; i++) f[i] = i + 1; sort(all.begin(), all.end()); int t = 0; for (auto [v, k]: all){ while (n < v){ b[t++] = f[k]; f[k] = ++n; } } return t; } int bin_pow(int x, int n){ if (!n) return 1; int out = x, pr = x; n--; while (n > 0){ if (n & 1){ out = (1LL * out * pr) % mod; } pr = (1LL * pr * pr) % mod; n >>= 1; } return out; } int countReplacement(int n, int a[]){ if (!valid(n, a)) return 0; vector<int> all; for (int i = 0; i < n; i++){ if (a[i] > n){ all.pb(a[i]); } } sort(all.begin(), all.end()); int pre = n, out = 1; for (int i = 0; i < all.size(); i++){ out = (1LL * out * bin_pow((int) all.size() - i, all[i] - pre - 1)) % mod; pre = all[i]; } if (all.size() == n){ out = (1LL * out * n) % mod; } return out; }
#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...