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;
typedef long long ll;
ll niz[100005];
ll niz1[100005];
map <ll, bool> bio;
const int MOD = 1000000009;
ll mul(ll a, ll b){
return (a*b)%MOD;
}
int pw(int a, int b){
if(b == 0) return 1;
int res = pw(a, b/2);
res = mul(res, res);
if(b%2) res = mul(res, a);
return res;
}
void shiftuj(int n, int k){
for(int i=1; i<=n; i++) niz1[i] = niz[i];
if(k < 0) k += n;
for(int i=k+1; i<=n; i++){
niz[i] = niz1[i-k];
}
for(int i=1; i<=k; i++){
niz[i] = niz1[n-k+i];
}
}
int valid(int n, int inputSeq[]){
for(int i=1; i<=n; i++){
niz[i] = inputSeq[i-1];
}
for(int i=1; i<=n; i++){
if(niz[i] <= n){
shiftuj(n, niz[i]-i);
break;
}
}
for(int i=1; i<=n; i++){
if(niz[i] <= n && niz[i] != i) return 0;
if(bio[niz[i]]) return 0;
bio[niz[i]] = 1;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
for(int i=1; i<=n; i++) niz[i] = gondolaSeq[i-1];
for(int i=1; i<=n; i++){
if(niz[i] <= n){
shiftuj(n, niz[i]-i);
break;
}
}
vector <pair <int, int>> vec;
for(int i=1; i<=n; i++){
if(niz[i] != i){
vec.push_back({niz[i], i});
}
}
sort(vec.begin(), vec.end());
int prosli = n+1;
int l = 0;
for(auto par : vec){
int a = par.first;
int b = par.second;
replacementSeq[l++] = b;
while(prosli < a){
replacementSeq[l++] = prosli;
prosli++;
}
prosli++;
}
return l;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
vector <pair <ll, ll>> vec;
for(ll i=1; i<=n; i++){
if(niz[i] != i){
vec.push_back({niz[i], i});
}
}
sort(vec.begin(), vec.end());
ll prosli = n+1;
ll g = vec.size();
ll sol = 1;
for(auto par : vec){
ll a = par.first;
ll b = par.second;
sol = mul(sol, pw(g, max(0LL, a-prosli)));
prosli = a+1;
g--;
}
if(vec.size() == n) sol = mul(sol, n);
return sol;
}
Compilation message (stderr)
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:103:12: warning: unused variable 'b' [-Wunused-variable]
ll b = par.second;
^
gondola.cpp:108:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(vec.size() == n) sol = mul(sol, 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... |