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 f0(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
const long long mod = 1e9 + 9;
long long powMod(long long a, long long b) {
long long res = 1;
while(b) {
if(b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int valid(int n, int inputSeq[]) {
set<int> s;
f0(i, n) {
s.insert(inputSeq[i]);
}
if(s.size() != n) return 0;
f0(i, n) {
if(inputSeq[i] <= n) {
f0(j, n) {
if(inputSeq[(i+j)%n] <= n) {
if((inputSeq[(i+j)%n] - inputSeq[i] + n) % n != j)
return 0;
}
}
break;
}
}
return 1;
return -1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int mx = -1;
f0(i, n) mx = max(mx, gondolaSeq[i]);
bool used[mx + 1] = {false};
f0(i, n) used[gondolaSeq[i]] = true;
int l = mx - n;
f0(i, l) replacementSeq[i] = -1;
int delta = 0;
f0(i, n) {
if(gondolaSeq[i] <= n) {
delta = (gondolaSeq[i] - i - 1 + n) % n;
break;
}
}
f0(i, n) {
if(gondolaSeq[i] > n) {
if(gondolaSeq[i] == mx) {
int ind = l-1;
for(int j = mx; j > n; j--) {
if(!used[j]) {
replacementSeq[ind] = j;
ind = j - n - 1;
}
}
replacementSeq[ind] = (i + delta) % n + 1;
} else {
replacementSeq[gondolaSeq[i] - n - 1] = (i + delta) % n + 1;
}
}
}
return l;
return -2;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
int val = valid(n, inputSeq);
if(val == 0) return 0;
long long res = 1;
long long bigCnt = 0, mx = 0;
f0(i, n) {
if(inputSeq[i] > n) {
bigCnt++;
}
mx = max(mx, (long long)inputSeq[i]);
}
bool used[mx + 1] = {false};
f0(i, n) used[inputSeq[i]] = true;
int cnt = 0;
for(int i = n+1; i <= mx; i++) {
if(!used[i]) cnt++;
else {
res = (res * powMod(bigCnt, cnt)) % mod;
cnt = 0;
bigCnt--;
}
}
return res;
return -3;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
28 | if(s.size() != n) return 0;
| ~~~~~~~~~^~~~
# | 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... |