# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
422842 | APROHACK | Gondola (IOI14_gondola) | C++14 | 75 ms | 5068 KiB |
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 PB push_back
#define S second
#define F first
using namespace std;
int valid(int n, int inputSeq[])
{
set<int>ocurr;
/*
for(int i = 0 ; i < 250001 ; i++){
ocurr[i]=false;
}*/
//bool pst=false;
int cur=-1;
for(int i = 0 ; i < n ; i++){
if((ocurr.find(inputSeq[i]))!=ocurr.end()){
return 0;
}
ocurr.insert(inputSeq[i]);
if(inputSeq[i]<=n){
if(cur==-1){
cur=inputSeq[i];
}else{
if(inputSeq[i]!=cur)return 0;
}
}
if(cur!=-1)cur++;
if(cur==n+1)cur=1;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int pos=-1;
vector<pair<int, int> >wow;
int mascara[n];
for(int i = 0 ; i < n ; i++){
if(gondolaSeq[i]>n){
wow.PB({gondolaSeq[i], i});
}else{
pos=i;
}
}
int cur=gondolaSeq[pos];
for(int i = pos ; i >=0 ; i--){
mascara[i]=cur;
cur--;
if(cur==0)cur=n;
}
cur=gondolaSeq[pos];
for(int i = pos ; i <n ; i++){
mascara[i]=cur;
cur++;
if(cur==n+1)cur=1;
}
int l, p=n+1, indx=0;
sort(wow.begin(), wow.end());//numero, indice
for(int i = 0 ; i < wow.size(); i++){
while(mascara[wow[i].S]<wow[i].F){
replacementSeq[indx]=mascara[wow[i].S];
mascara[wow[i].S]=p;
//cout<<replacementSeq[indx]<<endl;
p++;
indx++;
}
}
return indx;
}
//----------------------
long long pot(long long bas, long long exp){
if(exp==1)return bas;
if(exp==0)return 1;
long long ret=pot(bas, exp/2);
if(exp%2==0)return (ret*ret)%1000000009;
return (((ret*ret)%1000000009)*bas)%1000000009;
}
int countReplacement(int n, int inputSeq[])
{
if(valid(n, inputSeq)==0)return 0;
vector<long long >whew;
long long mxcur=n;
bool fixed=false;
for(int i = 0 ; i < n ; i++){
if(inputSeq[i]>n){
whew.PB(inputSeq[i]);
}else{
fixed=true;
}
}
long long rta = 1, MOD = 1000000009;
sort(whew.begin(), whew.end());
for(int i = 0 ; i < whew.size() ; i++){
long long nxt=(whew[i]), nums;
nums=(nxt-1)-(mxcur);
if(nums!=0&&(whew.size()-i)>1)rta*=pot((whew.size()-i), nums)%MOD;
rta%=MOD;
mxcur=nxt;
//wow.pop();
}
if(!fixed){
rta*=n;
rta%=MOD;
}
return rta;
}
Compilation message (stderr)
# | 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... |