Submission #1287792

#TimeUsernameProblemLanguageResultExecution timeMemory
1287792muhammad-mutahirBinaria (CCO23_day1problem1)C++20
3 / 25
9 ms8268 KiB
#include <bits/stdc++.h> using namespace std; #define print(l) for(auto i:l) cout<<i<<" ";cout<<endl; #define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i]; #define int long long #define pb push_back #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(l) l.begin(),l.end() #define pii pair<int,int> #define fi first #define se second const int M = 1e6+3; const int inf = 1e18; int bp(int x, int y, int p){ int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int MI(int n, int p){ return bp(n, p - 2, p); } int mul(int x,int y, int p){ return x * 1ull * y % p; } int di(int x,int y, int p){ return mul(x, MI(y, p), p); } int n , m , k , q; vector<int>fact; int cho(int n,int r){ if(r > n or r < 0){ return 0; } // return fact[n]/(fact[r]*fact[n-r]); return di(fact[n],mul(fact[n-r],fact[r],M),M); } void solve(int testcase_number){ cin>>n>>k; input(int,l,n-k+1); if(n == k){ cout<<cho(k,l[0])<<endl; return; } // print(l); // vector<int>l; // for(int i = 0;i<n-k+1;i++)l.pb(i%5); // print(l); // int ans1 = 0; // for(int i =0 ;i<(1<<k);i++){ // if(__builtin_popcount(i) != l[0])continue; // // vector<int>a(n+1,0); // for(int j = 0;j<k;j++){ // a[j] = (((1<<j)&i)!=0); // } // int p1 = 0; // int p2 = k; // int j = 1; // int sum = l[0]; // int f =1 ; // while(p2<=n and j<(int)l.size()){ // if(l[j] == sum-a[p1]+1){ // a[p2] = 1; // p2++; // p1++; // sum = l[j]; // j++; // } // else if(l[j] == sum-a[p1]){ // a[p2] = 0; // p2++; // p1++; // sum = l[j]; // j++; // } // else{ // f = 0; // // break; // } // // } // if(f){ // print(a); // ans1++; // } // // print(a); // // } // cout<<ans1<<endl; vector<int>a(n+1,-1); for(int i = 0;i+1<(int)l.size();i++){ if(l[i] > l[i+1]){ int j = -1; a[i] = 1; while(i+j*k >= 0){ if(i+j*k >= 0 and a[i+j*k] == -1 and l[i] == l[i+j]){ a[i+j*k] = a[i]; // cr--; j--; // break; } else{ break; } } a[i+k] = 0; j= 1; while(j<(int)l.size()){ if(i+k+j*(k)<n and a[i+k+j*k] == -1 and l[i+k] == l[i+k+j]){ // cout<<cr+j*k<<" "; a[i+k+j*(k)] = a[i+k]; // cr++; j++; // break; } else{ break; } } } else if(l[i]<l[i+1]){ a[i] = 0; int j = -1; while(i+j*k >= 0){ if(i+j*k >= 0 and a[i+j*k] == -1 and l[i] == l[i+j]){ a[i+j*k] = a[i]; // cr--; j--; // break; } else{ break; } } a[i+k] = 1; j = 1; while(j<(int)l.size()){ if(i+k+j*(k)<n and a[i+k+j*k] == -1 and l[i+k] == l[i+k+j]){ // cout<<cr+j*k<<" "; a[i+k+j*(k)] = a[i+k]; // cr++; j++; // break; } else{ break; } } } } // a = {1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1} // print(a); vector<int>pf = {0}; for(int i:a){ pf.pb(pf.back()+(i==1)); } // print(a); // print(pf); for(int i = 0;i<l.size();i++){ if(pf[i+k-1]-pf[i-1] == l[i]){ cout<<1<<endl; return; } } // print(a); int c1,c; c1 = c = 0; for(int i = 0;i<k;i++){ if(a[i] == -1){ c++; } if(a[i] == 1){ c1++; } } // cout<<c1<<" "<<c<<endl; cout<<cho(c,l[0]-c1)<<endl; // vector<int>cnt,cnt1; // cnt1 = {0}; // cnt = cnt1; // for(int i:a){ // cnt.pb(cnt.back()+(i == -1)); // cnt1.pb(cnt1.back()+(i == 1)); // } // int ans = 1e9; // int ans2; // int val; // for(int i = 0;i<n-k;i++){ // int le = i+1; // int ri = i+k; // int cntn1 = cnt[ri]-cnt[le-1]; // int cn1 = cnt1[ri]-cnt1[le-1]; // if(cntn1 < ans){ // ans = cntn1; // ans2 = cn1; // val = l[i]; // } // cout<<cho(cnt[ri]-cnt[le],l[i]-(cnt1[ri]-cnt1[le-1]))<<" "<<le<<" "<<ri<<endl; // if(cho(cnt[ri]-cnt[le],l[i]-(cnt1[ri]-cnt1[le-1])) >=1) // ans = min(ans,cho(cnt[ri]-cnt[le],l[i]-(cnt1[ri]-cnt1[le-1]))); // } // print(a); // cout<<an // cout<<cho(ans,val-ans2)<<endl; // cout<<ans%M<<endl; // int k1 = 0; // int c1= 0; // for(int i =0;i<k;i++){ // if(a[i] == -1){ // k1++; // } // else{ // if(a[i] == 1){ // c1++; // } // } // } // int k2 = 0; // int c2= 0; // for(int i = n-1;i>=n-k;i--){ // if(a[i] == -1){ // k2++; // } // if(a[i] == 1){ // c2++; // } // } // if(ans1<min(cho(k2,l.back()-c2),cho(k1,l[0]-c1))){ // int tt = 0; // while(1){ // tt++; // } // } // cout<<min(cho(k2,l.back()-c2),cho(k1,l[0]-c1))<<endl; } signed main(){ ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE cin.tie(0), cout.tie(0); cout << fixed<<setprecision(9); fact.resize(1e6+12,0); fact[0] = 1; for(int i = 1;i<=1e6+10;i++){ fact[i] = fact[i-1]*i; fact[i]%=M; } int t = 1; // cin>>t; for(int i = 1;i<=t;i++){ solve(i); } }
#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...