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[]) {
int newSeq[n + 1];
for(int i = 1; i <= n; i++) {
newSeq[i] = n + 1;
}
for(int i = 0; i < n; i++) {
if(inputSeq[i] >= 1 && inputSeq[i] <= n) {
newSeq[inputSeq[i]] = inputSeq[i];
int pos = i;
for(int j = inputSeq[i] + 1; j <= n; j++) {
pos++;
if(pos == n) {
pos = 0;
}
newSeq[j] = inputSeq[pos];
}
for(int j = 1; j <= inputSeq[i] - 1; j++) {
pos++;
if(pos == n) {
pos = 0;
}
newSeq[j] = inputSeq[pos];
}
break;
}
}
map<int, int> mp;
for(int i = 1; i <= n; i++) {
if(mp.count(newSeq[i])) {
return 0;
}
mp[newSeq[i]] = 1;
if(newSeq[i] >= 1 && newSeq[i] <= n && newSeq[i] != i) {
return 0;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int diff = 1e8, maxx = 0, pos = 0;
map<int, int> mp;
for(int i = 1; i <= n; i++) {
mp[gondolaSeq[i]] = i;
maxx = max(maxx, gondolaSeq[i]);
if(gondolaSeq[i] == maxx) {
pos = i;
}
if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n) {
int temp = gondolaSeq[i] - i;
if(diff == 1e8 || diff == temp || diff == temp - n || diff == temp + n) {
diff = temp;
}
else {
assert(false);
}
}
}
for(int i = 1; i <= n; i++) {
int x = diff + i;
if(x <= 0) {
x += n;
}
if(x > n) {
x -= n;
}
gondolaSeq[i] = x;
}
int rPos = 0;
for(int i = n + 1; i <= maxx; i++) {
if(!mp.count(i)) {
replacementSeq[rPos++] = gondolaSeq[pos];
gondolaSeq[pos] = i;
}
else {
replacementSeq[rPos++] = gondolaSeq[mp[i]];
gondolaSeq[mp[i]] = i;
}
}
return rPos;
}
const long long MOD = 1e9 + 9;
int countReplacement(int n, int inputSeq[]) {
long long diff = 1e8, maxx = 0;
map<long long, long long> mp;
long long NotinBetween = n;
for(long long i = 1; i <= n; i++) {
mp[inputSeq[i]] = i;
maxx = max(maxx, (long long)inputSeq[i]);
if(inputSeq[i] >= 1 && inputSeq[i] <= n) {
NotinBetween--;
long long temp = inputSeq[i] - i;
if(diff == 1e8 || diff == temp || diff == temp - n || diff == temp + n) {
diff = temp;
}
else {
return 0;
}
}
}
long long ans = 1;
for(long long i = n + 1; i <= maxx; i++) {
if(mp.count(i)) {
NotinBetween--;
}
else {
ans *= NotinBetween;
ans %= MOD;
}
}
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... |