# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953574 | irmuun | Gondola (IOI14_gondola) | C++17 | 32 ms | 5212 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<bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int valid(int n, int in[]){
int mn=n+1,pos=-1;
map<int,bool>used;
for(int i=0;i<n;i++){
if(used[in[i]]){
return 0;
}
used[in[i]]=true;
if(in[i]<=n){
if(in[i]<mn){
mn=in[i];
pos=i;
}
}
}
if(pos==-1) return 0;
for(int i=0;i<n;i++){
int p=(pos+i)%n;
if(in[p]<=n){
if(in[p]!=mn+i) return 0;
}
}
return 1;
}
int replacement(int n, int gon[], int rep[]){
int mx=0;
vector<pair<int,int>>v;
int a[n];
iota(a,a+n,1);
int mn=n+1,pos=-1;
for(int i=0;i<n;i++){
if(gon[i]<=n){
if(gon[i]<mn){
mn=gon[i];
pos=i;
}
}
}
if(pos>-1){
for(int i=0;i<n;i++){
a[(i+pos)%n]=mn;
mn=mn+1;
if(mn>n) mn=1;
}
}
for(int i=0;i<n;i++){
if(gon[i]>n){
v.pb({gon[i],i});
}
}
sort(all(v));
for(int i=0;i<v.size();i++){
}
int l=n+1,cur=0;
for(int i=0;i<v.size();i++){
int bef=a[v[i].ss];
for(;l<=v[i].ff;l++){
rep[cur++]=bef;
bef=l;
}
}
return cur;
}
const int mod=1e9+9;
int binpow(int a,int b){
int res=1;
while(b){
if(b&1){
res=1ll*res*a%mod;
}
a=1ll*a*a%mod;
b=b>>1;
}
return res;
}
int countReplacement(int n, int in[]){
int ans=valid(n,in);
if(ans==0) return 0;
bool flag=false;
for(int i=0;i<n;i++){
if(in[i]<=n){
flag=true;
}
}
if(!flag){
ans=n;
}
vector<int>v;
for(int i=0;i<n;i++){
if(in[n]>n){
v.pb(in[n]);
}
}
int left=n-v.size(),last=n;
sort(all(v));
for(int i=0;i<v.size();i++){
ans=1ll*ans*binpow(left,v[i]-last-1)%mod;
last=v[i];
left--;
}
return ans;
}
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... |