This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |