#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int valid(int n, int inputSeq[])
{
int p = 0;
for (int i = 0; i < n; i++) {
if (inputSeq[i] <= n) {
p = i-(inputSeq[i]-1);
if (p < 0) {
p+=n;
}
break;
}
}
map<int, bool> mp;
for (int i = 0; i < n; i++) {
if (inputSeq[i] <= n) {
if ((i-p+n)%n != inputSeq[i]-1) {
return 0;
}
}
else {
if (mp[inputSeq[i]]) {
return 0;
}
mp[inputSeq[i]] = 1;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int p = 0;
for (int i = 0; i < n; i++) {
if (gondolaSeq[i] <= n) {
p = i-(gondolaSeq[i]-1);
if (p < 0) {
p+=n;
}
break;
}
}
vector<pair<int, int>> x;
for (int i = 0; i < n; i++) {
if (gondolaSeq[i] > n) {
x.push_back({gondolaSeq[i], i});
}
}
sort(x.begin(), x.end());
int w = n, in = 0;
for (auto i : x) {
int k = i.second-p+1;
if (k <= 0) {
k += n;
}
replacementSeq[in] = k;
in++;
w++;
while (w < i.first) {
replacementSeq[in] = w;
in++;
w++;
}
}
return in;
}
//----------------------
ll M = 1e9+9;
ll pow(ll a, ll b) {
if (b == 0) {
return 1;
}
ll x = pow(a, b/2);
x = (x*x)%M;
if (b%2) {
x *= a;
}
return x%M;
}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq)) {
return 0;
}
ll w = 1, l = 0;
vector<ll> x;
for (int i = 0; i < n; i++) {
if (inputSeq[i] > n) {
x.push_back(inputSeq[i]);
l++;
}
}
sort(x.begin(), x.end());
ll p = n;
for (ll i : x) {
w *= pow(l, i-p-1);
w %= M;
l--;
p = i;
}
return (int)w;
}
# | 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... |