이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifndef ARTHUR_LOCAL
#include "gondola.h"
#endif
using namespace std;
using ll = long long;
bool used[250001];
const ll p = 1000000009;
ll modpow(ll a, int b)
{
if(b==0) return 1LL;
ll cur = modpow(a,int(b/2));
cur*=cur;
cur%=p;
if(b%2 == 1) cur*=a;
cur%=p;
return cur;
}
int valid(int n, int S[])
{
pair<int,int> minn = {int(1e9),int(1e9)};
for(int i=0; i<n; i++)
{
if(used[S[i]]) return 0;
used[S[i]]=1;
minn = min(minn, make_pair(S[i],i));
}
int cur = minn.first;
if(cur>n) return 1;
int one_pos = (minn.second - minn.first + 1 + n)%n;
for(int j=0; j<n; j++)
{
if(S[(one_pos+j)%n] == j+1 || S[(one_pos+j)%n]>n) continue;
return 0;
}
return 1;
}
int replacement(int n, int G[], int R[])
{
pair<int,int> minn = {int(1e9),int(1e9)};
for(int i=0; i<n; i++)
{
minn = min(minn, make_pair(G[i],i));
}
int cur = minn.first;
int one_pos = (minn.second - minn.first + 1 + n)%n;
if(cur>n) one_pos=0;
vector<pair<int,int>> reps;
for(int j=0; j<n; j++)
{
if(G[(one_pos+j)%n] == j+1) continue;
reps.push_back(make_pair(G[(one_pos+j)%n],j+1));
}
sort(reps.begin(),reps.end());
int ans=0;
int next_boat=n+1;
for(auto rep:reps)
{
int cur = rep.second;
for(int i=next_boat; i<=rep.first; i++)
{
// cout << cur << endl;
R[ans] = cur;
cur=next_boat;
ans++;
next_boat++;
}
}
// cout << endl;
return ans;
}
int countReplacement(int n, int S[])
{
pair<int,int> minn = {int(1e9),int(1e9)};
for(int i=0; i<n; i++)
{
if(used[S[i]]) return 0;
used[S[i]]=1;
minn = min(minn, make_pair(S[i],i));
}
int cur = minn.first;
int one_pos = (minn.second - minn.first + 1 + n)%n;
if(cur>n) one_pos=0;
for(int j=0; j<n; j++)
{
if(S[(one_pos+j)%n] == j+1 || S[(one_pos+j)%n]>n) continue;
return 0;
}
vector<int> V={0};
for(int j=0; j<n; j++)
{
if(S[(one_pos+j)%n] == j+1) continue;
V.push_back(S[(one_pos+j)%n]-n);
}
if(V.size()==1) return 1;
sort(V.begin(),V.end());
ll ans=1;
for(int i=1; i<int(V.size()); i++)
{
ans*=modpow(V.size()-i,V[i]-V[i-1]-1);
ans%=p;
}
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... |