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[]){
set<int> s;
map<int,int> pos;
for(int i = 0;i<n;i++){
s.insert(inputSeq[i]);
pos[inputSeq[i]] = i;
}
if(s.size() != n)return 0;
int num = *s.begin() + 1;
while(num <= n){
if(s.count(num) && pos[num] != (pos[*s.begin()] + num - *s.begin())%n){
return 0;
}
num++;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int pos_mini = 0;
int maxi = 0;
for(int i = 0;i<n;i++){
if(gondolaSeq[i] < gondolaSeq[pos_mini]){
pos_mini = i;
}
maxi = max(maxi,gondolaSeq[i]);
}
for(int i = 0;i<n;i++){
if(gondolaSeq[i] <= n){
pos_mini = (i - gondolaSeq[i] + 1 + n)%n;
}
}
int tmp[n];
map<int,int> mp;
for(int i = 0;i<n;i++)tmp[i] = gondolaSeq[i];
for(int i = 0;i<n;i++){
gondolaSeq[i] = tmp[(pos_mini + i)%n];
mp[gondolaSeq[i]] = i + 1;
//cout << gondolaSeq[i] << " ";
}
//cout << endl;
for(int i = n+1;i<=maxi;i++){
if(mp[i]){
replacementSeq[i - n - 1] = mp[i];
}
else{
replacementSeq[i - n - 1] = mp[maxi];
mp[maxi] = i;
}
}
return maxi - n;
}
//----------------------
const int mod = 1e9 + 9;
long long binpow(long long a,long long b){
long long ret = 1;
while(b){
if(b & 1)
ret = ret * a %mod;
a = a*a%mod;
b >>=1;
}
return ret;
}
int countReplacement(int n, int gondolaSeq[]){
if(!valid(n,gondolaSeq))return 0;
int pos_mini = 0;
int maxi = 0;
for(int i = 0;i<n;i++){
if(gondolaSeq[i] < gondolaSeq[pos_mini]){
pos_mini = i;
}
maxi = max(maxi,gondolaSeq[i]);
}
for(int i = 0;i<n;i++){
if(gondolaSeq[i] <= n){
pos_mini = (i - gondolaSeq[i] + 1 + n)%n;
}
}
int tmp[n];
map<int,int> mp;
for(int i = 0;i<n;i++)tmp[i] = gondolaSeq[i];
for(int i = 0;i<n;i++){
gondolaSeq[i] = tmp[(pos_mini + i)%n];
mp[gondolaSeq[i]] = i + 1;
//cout << gondolaSeq[i] << " ";
}
//cout << endl;
int unfixed = 0;
set<int> points;
for(int i = 0;i<n;i++){
if(gondolaSeq[i] > n){
points.insert(gondolaSeq[i]);
unfixed++;
}
}
int ret = 1;
if(unfixed == n){
ret = n;
}
int last = n;
for(auto u:points){
ret = ret * binpow(unfixed,u -last -1)%mod;
last = u;
unfixed--;
}
return ret;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:11:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
11 | 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... |