제출 #577461

#제출 시각아이디문제언어결과실행 시간메모리
577461perchuts곤돌라 (IOI14_gondola)C++17
75 / 100
47 ms6100 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define pb push_back #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; using ll = long long; using ull = unsigned long long; using ii = pair<int,int>; using iii = tuple<int,int,int>; const int inf = 2e9+1; const int mod = 1e9+9; const int maxn = 1e5+100; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } #include "gondola.h" int valid(int n,int v[]){ vector<ii>v2; map<int,bool>mp; int mn = inf, idx = -1; for(int i=0;i<n;++i){ if(mp[v[i]]==1)return 0; mp[v[i]] = 1; if(ckmin(mn,v[i]))idx = i; } if(mn>=n)return 1; for(int i=idx;i<n;++i)if(v[i]<=n)v2.pb({v[i],i-idx}); for(int i=0;i<idx;++i)if(v[i]<=n)v2.pb({v[i],n-idx+i}); for(int i=1;i<sz(v2);++i){ if(v2[i].first-v2[i-1].first!=v2[i].second-v2[i-1].second)return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int mn = n+1, idx = 0; for(int i=0;i<n;++i){ if(ckmin(mn,gondolaSeq[i]))idx = i; } if(mn>n)mn = 1; vector<ii>ajusta; for(int i=idx;i<n;++i){ if(gondolaSeq[i]>n)ajusta.pb({gondolaSeq[i],mn}); mn++; if(mn>n)mn = 1; } for(int i=0;i<idx;++i){ if(gondolaSeq[i]>n)ajusta.pb({gondolaSeq[i],mn}); mn++; if(mn>n)mn = 1; } sort(all(ajusta)); int cur = n+1; idx = 0; for(auto [b,a]:ajusta){ while(a!=b){ replacementSeq[idx++] = a, a = cur++; } } return idx; } //---------------------- ll fastexp(ll b,ll e){ if(e==0)return 1ll; if(e==1)return b; ll sqr = fastexp(b,e/2), resp = (sqr*sqr)%mod; if(e&1)return (resp*b)%mod; return resp; } int countReplacement(int n, int inputSeq[]) { vector<ll>big; if(!valid(n,inputSeq))return 0; for(int i=0;i<n;++i){ if(inputSeq[i]>n)big.pb(ll(inputSeq[i])); } sort(all(big)); ll res = 1, last = n; for(int i=0;i<sz(big);++i){ res = (res*fastexp(ll(sz(big)-i),ll(big[i]-last-1)))%mod, last = big[i]; } return res; } // int v[maxn], resp[maxn]; // int main(){_ // int n;cin>>n; // for(int i=0;i<n;++i)cin>>v[i]; // cout<<countReplacement(n,v)<<endl; // }
#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...