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>
#define F first
#define S second
using namespace std;
const int mod = 1e9 + 9;
int valid(int n, int inputSeq[])
{
int mn_pos = 0;
for(int i = 1 ; i < n ; i++) if(inputSeq[i] < inputSeq[mn_pos])
mn_pos = i;
vector <int> vec;
for(int i = mn_pos ; i < n ; i++)
vec.push_back(inputSeq[i]);
for(int i = 0 ; i < mn_pos ; i++)
vec.push_back(inputSeq[i]);
set <int> st;
for(auto u : vec)
st.insert(u);
if(st.size() != n)
return 0;
bool flg = true;
for(int i = 1 ; i < n ; i++) if(vec[i] <= n && vec[i] - vec[0] != i)
flg = false;
return flg;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int mn_pos = 0;
for(int i = 1 ; i < n ; i++) if(gondolaSeq[i] < gondolaSeq[mn_pos])
mn_pos = i;
vector <int> vec;
for(int i = mn_pos ; i < n ; i++)
vec.push_back(gondolaSeq[i]);
for(int i = 0 ; i < mn_pos ; i++)
vec.push_back(gondolaSeq[i]);
int mx = 0;
for(int i = 0 ; i < n ; i++)
mx = max(mx , vec[i]);
int l = mx - n , pos = 0 , las = n;
vector <pair<int , int>> bad;
for(int i = 0 ; i < n ; i++) if(vec[i] > n)
bad.push_back(make_pair(vec[i] , i));
if(vec[0] > n)
vec[0] = 1;
for(int i = 1 ; i < n ; i++)
{
vec[i] = vec[i - 1] + 1;
if(vec[i - 1] == n)
vec[i] = 1;
}
sort(bad.begin() , bad.end());
for(auto u : bad)
{
while(las < u.F)
{
las++;
replacementSeq[pos] = vec[u.S];
vec[u.S] = las;
pos++;
}
}
return l;
}
int tav(int a , int b)
{
int res = 1;
while(b)
{
if(b & 1)
res = 1LL * res * a % mod;
b >>= 1;
a = 1LL * a * a % mod;
}
return res;
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n , inputSeq))
return 0;
vector <int> vec;
for(int i = 0 ; i < n ; i++) if(inputSeq[i] > n)
vec.push_back(inputSeq[i]);
int x = vec.size();
sort(vec.begin() , vec.end());
int ans = 1 , las = n;
for(auto u : vec)
{
ans = 1LL * ans * tav(x , u - las - 1) % mod;
las = u;
x--;
}
if(vec.size() == n)
ans = 1LL * ans * n % mod;
return ans;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
23 | if(st.size() != n)
| ~~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:99:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
99 | if(vec.size() == n)
| ~~~~~~~~~~~^~~~
# | 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... |