# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
374481 | Aryan_Raina | Gondola (IOI14_gondola) | C++14 | 126 ms | 4844 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9+9;
int valid(int n, int a[]) {
int rr = -1;
set<int> vis;
for (int i = 0; i < n; i++) {
if (vis.count(a[i])) return 0;
vis.insert(a[i]);
if (a[i] <= n) {
if (rr == -1) rr = i;
if ((n + a[i] - a[rr]) % n != (n + i - rr) % n) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int a[], int replacementSeq[]) {
if (!valid(n, a)) return 0;
int rr = -1;
for (int i = 0; i < n; i++) {
if (a[i] <= n) {
rr = i; break;
}
}
vector<array<int,2>> rep;
for (int i = 0; i < n; i++) {
if (a[i] > n) {
int x = (a[rr] + i - rr + n) % n;
if (x == 0) x = n;
rep.push_back({a[i], x});
}
}
sort(rep.begin(), rep.end());
int ind = 0, last = n+1;
for (int i = 0; i < rep.size(); ++i) {
replacementSeq[ind++] = rep[i][1];
last++;
for (; last <= rep[i][0]; ++last) replacementSeq[ind++] = last-1;
}
return ind;
}
//----------------------
ll modpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = (res*a)%MOD;
a = (a*a)%MOD;
b>>=1;
}
return res;
}
int countReplacement(int n, int a[]) {
if (!valid(n, a)) return 0;
vector<int> rep;
for (int i = 0; i < n; i++) {
if (a[i] > n) {
rep.push_back(a[i]);
}
}
sort(rep.begin(), rep.end());
ll ans = 1, last = n+1;
int sz = rep.size();
for (int i = 0; i < sz; i++) {
ans = (ans * modpow(sz-i, rep[i] - last)) % MOD;
last = rep[i]+1;
}
return ans;
}
Compilation message (stderr)
# | 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... |