Submission #1287758

#TimeUsernameProblemLanguageResultExecution timeMemory
1287758muhammad-mutahirBinaria (CCO23_day1problem1)C++20
0 / 25
1096 ms8260 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 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); // 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){ 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]){ a[i] = 1; a[i+k] = 0; // int t = i+k; // int j = 1; // while(t<l.size() and l[i+j] ==l[t]){ // a[i+k+k*j] = 0; // t+=k; // j++; // } } else if(l[i]<l[i+1]){ a[i] = 0; a[i+k] = 1; // int t = i+k; // int j = 1; // while(t<l.size() and l[i+j] ==l[t]){ // a[i+k+k*j] = 1; // t+=k; // j++; // } } } int k1 = 0; int c1= 0; for(int i =0;i<k;i++){ if(a[i] == -1){ k1++; } else{ if(a[i] == 1){ c1++; } } } if(ans1 != cho(k1,l[0]-c1) and k == 3){ if(l[2] == 1){ int t= 0; while(1){ t++; } } else if(l[2] == 3){ vector<int>tst; tst[100]++; } else{ cout<<cho(k1,l[0]-c1)<<endl; } }else{ cout<<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...