Submission #1008969

#TimeUsernameProblemLanguageResultExecution timeMemory
1008969hotboy2703Gondola (IOI14_gondola)C++14
75 / 100
34 ms4664 KiB
#include "gondola.h" #include<bits/stdc++.h> using namespace std; using ll = long long; #define pll pair <ll,ll> #define fi first #define se second #define MP make_pair #define sz(a) (ll((a).size())) #define BIT(mask,i) (((mask) >> (i))&1) #define MASK(i) (1LL << (i)) int valid(int n, int a[]) { set <ll> s; for (ll i = 0,expected = -n;i < n;i ++,expected=expected+1>n?1:expected+1){ if (s.insert(a[i]).se==0)return 0; if (a[i] > n)continue; if (expected < 0)expected = a[i]; if (expected != a[i])return 0; } return 1; } //---------------------- int replacement(int n, int a[], int ans[]) { ll ptr = 0; vector <ll> b(n); iota(b.begin(),b.end(),1); for (ll i = 0;i < n;i ++){ if (a[i] <= n){ b[i] = a[i]; for (ll j = i + 1;j < n;j ++){ b[j] = b[j-1]+1; if (b[j] > n)b[j] = 1; } for (ll j = i - 1;j >= 0;j--){ b[j] = b[j+1]-1; if (b[j]==0)b[j] = n; } break; } } vector <pll> all; for (ll i = 0;i < n;i ++){ if (a[i] > n){ all.push_back(MP(a[i],b[i])); } } sort(all.begin(),all.end()); ll last = n; for (auto x:all){ last++; ans[ptr++]=x.se; for (ll i = last+1;i<=x.fi;i++)ans[ptr++]=i-1; last = x.fi; } return ptr; } //---------------------- const ll MOD = 1e9 + 9; ll p(ll x,ll y){ ll res = 1; // cout<<x<<' '<<y<<'\n'; for (;y;y>>=1,x=x*x%MOD)if (y&1)res=res*x%MOD; return res; } int countReplacement(int n, int a[]) { if (!valid(n,a))return 0; bool ok = 0; vector <ll> all; for (ll i = 0;i < n;i ++){ if (a[i] <= n){ ok = 1; } else{ all.push_back(a[i]); } } ll res = 1; if (!ok){ for (ll i = 1;i <= n; i++)res = res*i%MOD; } sort(all.begin(),all.end()); ll last = n; for (ll j = 0;j < sz(all);j ++){ // cout<<sz(all)-j<<' '<<all[j]-last-1<<' '<<p(sz(all)-j,all[j]-last-1)<<'\n'; res = res*p(sz(all)-j,all[j]-last-1)%MOD; last = all[j]; } return res; }
#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...