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 <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define pii pair<int, int>
#define fst first
#define snd second
#define ll long long
const int MD = 1e9 + 9;
using namespace std;
inline ll pw(ll b, ll e)
{
ll t = 1;
while (e)
{
if (e & 1) {t = (t * b) % MD;}
b = (b * b) % MD; e >>= 1;
}
return t;
}
int valid(int n, int inputSeq[])
{
unordered_map<int, int> cnt; int sp = -1;
for (int i = 0; i < n; i++)
{
if (inputSeq[i] <= n)
{
if (sp == -1) sp = (i + (n + 1 - inputSeq[i])) % n;
else if (sp != (i + (n + 1 - inputSeq[i])) % n) {return 0;}
}
cnt[inputSeq[i]]++;
if (cnt[inputSeq[i]] > 1) {return 0;}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int sp = -1, lg = 0;
vector<pii> v;
for (int i = 0; i < n; i++)
{
if (gondolaSeq[i] <= n) {sp = (i + (n + 1 - gondolaSeq[i])) % n;}
else {v.push_back({gondolaSeq[i], i});}
}
if (sp == -1) {sp = 0;}
sort(v.begin(), v.end());
for (auto &x : v)
{
replacementSeq[lg++] = (x.snd + n - sp) % n + 1;
while (lg + n < x.fst) {replacementSeq[lg] = n + lg; lg++;}
}
return lg;
}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq)) {return 0;}
vector<int> v; int sp = -1;
for (int i = 0; i < n; i++)
{
if (inputSeq[i] > n) {v.push_back(inputSeq[i]);}
else {sp = 0;}
}
sort(v.begin(), v.end());
int pv = n; long long res = 1;
for (int i = 0; i < v.size(); i++)
{
res = (res * pw(v.size() - i, v[i] - pv - 1)) % MD;
pv = v[i];
}
if (sp == -1) {res = (res * n) % MD;}
return res;
}
Compilation message (stderr)
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); i++)
~~^~~~~~~~~~
# | 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... |