# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
414056 | dxz05 | Gondola (IOI14_gondola) | C++14 | 40 ms | 5620 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;
const int MAXN = 3e5 + 2e2;
int a[MAXN];
int valid(int n, int inputSeq[]){
for (int i = 0; i < 3 * n; i++) a[i] = inputSeq[i % n];
set<int> s;
for (int i = 0; i < n; i++) s.insert(a[i]);
if (s.size() != n) return 0;
int ind = -1;
for (int i = n; i < 2 * n; i++){
if (a[i] <= n){
ind = i;
break;
}
}
if (ind == -1) return 1;
for (int i = ind - a[ind] + 1; i <= ind - a[ind] + n; i++){
if (a[i] > n) continue;
if (a[i] - a[ind] != i - ind) return 0;
}
return 1;
}
//----------------------
int orig[MAXN];
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
for (int i = 0; i < n; i++){
a[i] = gondolaSeq[i];
orig[i] = i + 1;
}
for (int i = 0; i < n; i++){
if (a[i] <= n){
int ind = 1;
for (int j = i - a[i] + 1; j <= i - a[i] + n; j++){
orig[(j + n) % n] = ind++;
}
break;
}
}
set<pair<int, int>> s;
for (int i = 0; i < n; i++){
s.insert(make_pair(a[i], orig[i]));
}
int last = n;
int sz = 0;
while (!s.empty()){
int cur = s.begin()->second, need = s.begin()->first;
s.erase(s.begin());
if (cur == need) continue;
replacementSeq[sz++] = cur;
last++;
while (last < need){
replacementSeq[sz++] = last;
last++;
}
}
return sz;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if (valid(n, inputSeq) == 0) return 0;
for (int i = 0; i < n; i++){
a[i + 1] = inputSeq[i];
}
sort(a + 1, a + n + 1);
if (a[n] == n) return 1;
int j = 1;
long long ans = 1, MOD = 1e9 + 9;
if (n == 2 && a[1] > 2) ans = 2;
for (int x = n + 1; x <= a[n]; x++){
while (j <= n && a[j] < x) j++;
if (a[j] == x) continue;
ans *= n - j + 1;
ans %= MOD;
}
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... |