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 = n;
// long long bigCnt = 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;
vector<int> used = {n};
f0(i, n) {
if(inputSeq[i] > n) {
used.push_back(inputSeq[i]);
} else {
res = 1;
}
}
int bigCnt = used.size() - 1;
sort(used.begin(), used.end());
int nn = used.size();
f0(i, nn-1) {
int cnt = used[i+1] - used[i] - 1;
res = (res * powMod(bigCnt, cnt)) % mod;
bigCnt--;
}
// cout << bigCnt << endl;
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... |