# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587116 | Jomnoi | Gondola (IOI14_gondola) | C++17 | 35 ms | 5184 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 <bits/stdc++.h>
#include "gondola.h"
using namespace std;
const int MOD = 1e9 + 9;
int valid(int n, int inputSeq[]) {
set <int> s;
int pos = -1;
for(int i = 0; i < n; i++) {
s.insert(inputSeq[i]);
if(inputSeq[i] <= n) {
pos = i;
}
}
if(s.size() < n) {
return 0;
}
if(pos == -1) {
return 1;
}
int start = (inputSeq[pos] - pos - 1 + 2 * n) % n + 1;
for(int i = 0; i < n; i++) {
if(inputSeq[i] <= n and inputSeq[i] != (start + i - 1) % n + 1) {
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
map <int, int> location;
int start = 1, max_val = 0;
for(int i = 0; i < n; i++) {
if(gondolaSeq[i] <= n) {
start = (gondolaSeq[i] - i - 1 + 2 * n) % n + 1;
}
max_val = max(max_val, gondolaSeq[i]);
location[gondolaSeq[i]] = i;
}
int j = n + 1, len = 0;
for(int i = n + 1; i <= max_val; i++) {
if(!location.count(i)) {
continue;
}
replacementSeq[len++] = (location[i] + start - 1) % n + 1;
while(j < i) {
if(!location.count(j)) {
replacementSeq[len++] = j;
}
j++;
}
}
return len;
}
//----------------------
long long expo(int x, int y) {
if(y == 0) {
return 1;
}
long long res = expo(x, y / 2);
res = res * res % MOD;
if(y % 2 == 1) {
res = res * x % MOD;
}
return res;
}
int countReplacement(int n, int inputSeq[]) {
if(valid(n, inputSeq) == 0) {
return 0;
}
vector <int> newGondola;
for(int i = 0; i < n; i++) {
if(inputSeq[i] > n) {
newGondola.push_back(inputSeq[i]);
}
}
sort(newGondola.begin(), newGondola.end());
long long ans = 1;
int prev = n;
for(int i = 0; i < newGondola.size(); i++) {
ans = ans * expo(newGondola.size() - i, newGondola[i] - prev - 1) % MOD;
prev = newGondola[i];
}
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... |