Submission #238991

#TimeUsernameProblemLanguageResultExecution timeMemory
238991tleontest1Gondola (IOI14_gondola)C++14
75 / 100
25 ms3444 KiB
#include <stdio.h> #include <assert.h> #include "gondola.h" //~ int gondolaSequence[1000001]; //~ int replacementSequence[2500001]; #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo MAX = -1000000000000000000; const lo MIN = 1000000000000000000; const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 5000005; const lo mod = 1000000009; int m,k,flag,t,vis[li],visit[li],c[li]; int cev; string s; vector<lo> v; lo mul(lo x,lo y){ return (x%mod)*(y%mod)%mod; } lo fp(lo x,lo y){ if(y==0)return 1; if(y==1)return x; lo q=fp(x,y/2); q=mul(q,q); if(y%2)q=mul(q,x); return q; } int valid(int n, int a[]){ int con=-1; for(int i=0;i<n;i++){ if(a[i]<=n && con==-1){ if(i>=a[i]-1)con=i-(a[i]-1); else con=i+1+(n-a[i]); } else if(a[i]<=n){ int con1=0; if(i>=a[i]-1)con1=i-(a[i]-1); else con1=i+1+(n-a[i]); if(con1!=con)flag=1; } } sort(a,a+n); for(int i=1;i<n;i++){ if(a[i]==a[i-1])flag=1; } if(flag)return 0; return 1; } //---------------------- int replacement(int n, int a[], int replacementSequence[]){ int con=-1; for(int i=0;i<n;i++){ if(a[i]<=n && con==-1){ if(i>=a[i]-1)con=i-(a[i]-1); else con=i+1+(n-a[i]); } } FOR v.pb(i); vector<lo> vec=v; //~ for(int i=0;i<n;i++){ //~ int at=i-con; //~ if(at<0)at+=n; //~ v[at]=vec[i]; //~ } for(int i=0;i<n;i++){ c[i]=a[i]; } if(~con){ for(int i=0;i<n;i++){ int at=i-con; if(at<0)at+=n; a[at]=c[i]; } } for(int i=0;i<n;i++){ //~ if(a[i]<=n){visit[i]=1;continue;} vis[a[i]]=(i); } int maxi=n; int len=0; for(int i=0;i<(int)v.size();i++){ //~ if(visit[i]==1)continue; if(v[i]==a[i])continue; //~ cout<<v[i]<<" : : "<<b[i]<<endl; //~ if(vis[i]==) if(vis[maxi+1]==0){ replacementSequence[len++]=v[i]; v[i]=++maxi; i--; } else{ replacementSequence[len++]=v[vis[maxi+1]]; visit[vis[maxi+1]]=1; v[vis[maxi+1]]=maxi+1; maxi++; i--; } } return len; } int countReplacement(int n, int a[]){ lo carp=valid(n,a); cev=0; //~ lo mx=0; for(int i=0;i<n;i++){ if(a[i]>n)cev++; //~ mx=max(mx,(lo)a[i]); //~ vis[a[i]]=1; } //~ cout<<cev<<endl; sort(a,a+n); if(a[0]>n)v.pb(a[0]-n-1); for(int i=1;i<n;i++){ if(a[i]<=n)continue; v.pb(max(0,a[i]-a[i-1]-1)); } for(int i=0;i<(int)v.size();i++){ carp=mul(carp,fp(cev,v[i])); cev--; } //~ cout<<cev<<endl; return carp; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...