이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000009;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
#include "gondola.h"
int valid(int n, int inputSeq[]){
map<int,bool>use;
int i,ofset=-1;
for(i=0;i<n;i++){
if(use[inputSeq[i]]){return 0;}
use[inputSeq[i]]=1;
if(inputSeq[i]>n){continue;}
int itf=(i+n-inputSeq[i])%n;
if(ofset==-1||ofset==itf){ofset=itf;}
else{return 0;}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
int i,dai=0,ofset=0,ziyu=0;
for(i=0;i<n;i++){
if(maxeq(dai,gondolaSeq[i])){ziyu=i;}
if(gondolaSeq[i]>n){continue;}
int itf=(i+n-gondolaSeq[i])%n;
ofset=itf;
}
//場所-ofset=元のゴンドラ
for(i=0;i<dai-n;i++){replacementSeq[i]=-1;}
ziyu=(n+n+ziyu-ofset-1)%n +1;
for(i=0;i<n;i++){if(gondolaSeq[i]>n){replacementSeq[gondolaSeq[i]-n-1]=(n+n+i-ofset-1)%n +1;}}
for(i=0;i<dai-n;i++){
if(replacementSeq[i]==-1){
replacementSeq[i]=ziyu;
ziyu=i+n+1;
}
}
if(dai>n){replacementSeq[dai-n-1]=ziyu;}
return dai-n;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq)){return 0;}
llint dai=0,ans=n,zi=0,i;
for(i=0;i<n;i++){
maxeq(dai,inputSeq[i]);
if(inputSeq[i]<=n){ans=1;}
}
sort(inputSeq,inputSeq+n);
int mae=dai+1;
for(i=n-1;i>=0&&inputSeq[i]>n;i--){
int dis=mae-inputSeq[i]-1;
mae=inputSeq[i];
llint bg=zi;
for(int h=0;h<=30;h++){
if(dis&(1<<h)){ans*=bg;ans%=mod;}
bg*=bg;bg%=mod;
}
zi++;
}
int dis=mae-n-1;
llint bg=zi;
for(int h=0;h<=30;h++){
if(dis&(1<<h)){ans*=bg;ans%=mod;}
bg*=bg;bg%=mod;
}
return ans;
}
# | 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... |