Submission #1027551

#TimeUsernameProblemLanguageResultExecution timeMemory
1027551anHiepBinaria (CCO23_day1problem1)C++14
0 / 25
5 ms33116 KiB
#include<bits/stdc++.h> #ifdef LOCAL #include "D:\debug.h" #else #define cebug(...) "Orz_chUoNgnn_khanhtb_0x2ee08" #endif using namespace std; #define int long long #define fi first #define se second #define pb push_back #define ll long long #define ii pair<int, int> #define vi vector<int> #define vll vector<ll> #define vii vector<ii> #define cd complex<double> const ll mod = 1e6 + 3; const ll INF = 1e18L + 5; const double PI = acos(-1); const int block = 320; const int N = 1e6; int tc, tt = 1; int n, k; ll a[N + 5], b[N + 5]; vi g[N + 5]; int vis[N + 5]; ll powmod(ll a, ll b) { ll ans = 1; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b /= 2; } return ans; } void dfs(int root, int u, int par) { cerr<<root<<' '<<u<<'\n'; b[u] = b[root]; vis[u] = true; for(auto v: g[u]) if(!vis[v]) dfs(root, v, u); } void solve() { cin>>n>>k; memset(b, -1, sizeof(b)); for(int i=1; i<=n-k+1; i++) cin>>a[i]; for(int i=2; i<=n-k+1; i++) { if(abs(a[i] - a[i - 1]) > 1) { cout<<0<<'\n'; return; } if(a[i] == a[i - 1]) { g[i + k - 1].pb(i - 1); g[i - 1].pb(i + k - 1); } if(a[i] > a[i - 1]) { if(b[i - 1] == 1 || b[i + k - 1] == 0) { cout<<0<<'\n'; return; } b[i - 1] = 0; b[i + k - 1] = 1; } if(a[i] < a[i - 1]) { if(b[i - 1] == 0 || b[i + k - 1] == 1) { cout<<0<<'\n'; return; } b[i - 1] = 1; b[i + k - 1] = 0; } } for(int i=1; i<=n; i++) cerr<<b[i]<<' '; cerr<<'\n'; for(int i=1; i<=n; i++) if(b[i] != -1 && !vis[i]) dfs(i, i, -1); ll ans = 1, sum = 0, cnt = 0; for(int i=1; i<=k; i++) { if(b[i] == -1) cnt++; else sum += b[i]; } if(sum > a[1] || sum > cnt) { cout<<0<<'\n'; return; } sum = a[1] - sum; for(int i=cnt; i>=cnt - sum + 1; i--) ans = ans * i % mod; ll dem = 1; for(int i=1; i<=sum; i++) dem = dem * i % mod; ans = ans * powmod(dem, mod - 2) % mod; cout<<ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for(tc=1; tc<=tt; tc++) solve(); cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n"; return 0; }
#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...