이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+9;
int valid(int n, int inputSeq[]) {
int i;
set<int> chk;
for(i=0;i<n;i++) {
if(chk.count(inputSeq[i])) return 0;
chk.insert(inputSeq[i]);
}
int p=-1,t;
for(i=0;i<n;i++) {
if(inputSeq[i]<=n) {
t=(i-inputSeq[i]+1+n)%n;
if(p!=-1&&t!=p) return 0;
p=t;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int i,j,p=0;
for(i=0;i<n;i++) {
if(gondolaSeq[i]<=n) {
p=(i-gondolaSeq[i]+1+n)%n;
break;
}
}
vector<pii> v;
for(i=0;i<n;i++) {
if(gondolaSeq[i]>n) {
v.push_back(make_pair(gondolaSeq[i],i));
}
}
sort(all(v));
int cur=n,top=0;
for(i=0;i<sz(v);i++) {
if(v[i].se>=p) j=v[i].se-p+1;
else j=n-p+v[i].se+1;
replacementSeq[top++]=j;cur++;
while(cur<v[i].fi) replacementSeq[top++]=cur++;
}
return top;
}
//----------------------
int modpow(int a,int n) {
int r=1,b=a;
while(n>0) {
if(n&1) r=(ll)r*b%mod;
b=(ll)b*b%mod;
n>>=1;
}
return r;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n,inputSeq)) return 0;
vector<int> v;
int i;
for(i=0;i<n;i++) {
if(inputSeq[i]>n) v.push_back(inputSeq[i]);
}
if(v.empty()) return 1;
v.push_back(n);
sort(all(v));
int res=1;
for(i=0;i+1<sz(v);i++) {
res=(ll)res*modpow(sz(v)-i-1,v[i+1]-v[i]-1)%mod;
}
if(sz(v)==n+1) {
res=(ll)res*n%mod;
}
return res;
}
# | 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... |