# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718213 | thimote75 | Gondola (IOI14_gondola) | C++14 | 35 ms | 4624 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;
int valid(int n, int inputSeq[])
{
set<int> omega;
for (int i = 0; i < n; i ++) omega.insert(inputSeq[i]);
if (omega.size() != n) return 0;
int jStart = -1;
for (int i = 0; i < n; i ++) {
if (inputSeq[i] > n) continue ;
jStart = i;
break;
}
if (jStart == -1) return 1;
int start = jStart - inputSeq[jStart] + 1;
if (start < 0) start += n;
for (int mu = 0; mu < n; mu ++) {
int nu = (start + mu);
if (nu >= n) nu -= n;
if (inputSeq[nu] > n) continue ;
if (inputSeq[nu] != mu + 1)
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int maxValue = 0;
int maxPos = -1;
int jStart = -1;
for (int i = 0; i < n; i ++) {
if (gondolaSeq[i] > maxValue) {
maxValue = gondolaSeq[i];
maxPos = i;
}
if (gondolaSeq[i] <= n) {
jStart = i;
}
}
int start = 0;
if (jStart != -1) {
start = jStart - gondolaSeq[jStart] + 1;
if (start < 0) start += n;
}
int length = maxValue - n;
for (int i = 0; i < length; i ++) {
replacementSeq[i] = -1;
}
for (int i = 0; i < n; i ++) {
if (gondolaSeq[i] > n && gondolaSeq[i] != maxValue) {
replacementSeq[gondolaSeq[i] - n - 1] = (n + i - start) % n + 1;
}
}
int last = (n + maxPos - start) % n + 1;
for (int i = 0; i < length; i ++) {
int value = i + n + 1;
if (replacementSeq[i] != -1) continue ;
replacementSeq[i] = last;
last = value;
}
return length;
}
//----------------------
#define num long long
const num MOD = 1e9 + 9;
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq)) return 0;
bool includes_old = false;
for (int i = 0; i < n; i ++)
if (inputSeq[i] <= n)
includes_old = true;
int maxValue = 0;
set<int> omega;
for (int i = 0; i < n; i ++) {
if (inputSeq[i] > n)
omega.insert(inputSeq[i]);
maxValue = max(maxValue, inputSeq[i]);
}
num result = 1;
int delta = 0;
for (int l = n + 1; l <= maxValue; l ++) {
if (omega.find(l) != omega.end()) {
delta --;
continue ;
}
result *= omega.size() - delta;
if (result >= MOD)
result %= MOD;
}
if (!includes_old) {
result *= n;
result %= MOD;
}
return (int) result;
}
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... |