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 offset = -1;
for(int i = 0; i < n; i++){
if(inputSeq[i]<=n){
int tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int offset = -1;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for(int i = 0; i < n; i++){
if(gondolaSeq[i]<=n){
int tmp = (n+gondolaSeq[i]-i-1)%n;
if(offset==-1) offset = tmp;
}else{
q.push(make_pair(gondolaSeq[i], i));
}
}
if(offset==-1) offset=0;
for(int i = 0; i < n; i++){
gondolaSeq[i] = 1+(i+offset)%n;
}
int cur = n+1;
for(int i = 0; !q.empty(); i++){
if(gondolaSeq[q.top().second] < q.top().first){
replacementSeq[i] = gondolaSeq[q.top().second];
gondolaSeq[q.top().second] = cur;
cur++;
}else{
q.pop();
i--;
}
}
return cur-n-1;
return -2;
}
//----------------------
long long mod = 1e9+9;
long long pot(long long a, long long b){
if(b==0) return 1;
if(b%2==0){
long long cur = pot(a, b/2);
return (cur*cur)%mod;
}else return (a*pot(a, b-1))%mod;
}
int countReplacement(int n, int inputSeq[])
{
vector<int> tab;
int offset = -1;
long long wyn = 1;
int cnt = 0;
for(int i = 0; i < n; i++){
if(inputSeq[i]<=n){
int tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}else{
cnt++;
tab.push_back(inputSeq[i]);
}
}
sort(tab.begin(), tab.end());
int cur = n+1;
for(int i = 0; i < tab.size(); i++){
wyn*=pot(cnt, tab[i]-cur);
wyn%=mod;
cur=tab[i]+1;
cnt--;
}
return wyn;
}
Compilation message (stderr)
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:84:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i = 0; i < tab.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... |