Submission #932853

#TimeUsernameProblemLanguageResultExecution timeMemory
932853PotatoManBinaria (CCO23_day1problem1)C++14
0 / 25
0 ms348 KiB
#include <bits/stdc++.h> #define inf INT_MAX #define longlonginf LONG_LONG_MAX #define mod 1000003 #define MAXN 200005 #define pii pair<ll,ll> #define ll long long #define deb(x) cerr<<"[ "<<#x<<" = "<<x<<" ]"; #define yes() cout<<"YES\n"; #define no() cout<<"NO\n"; using namespace std; ll n,k,m,q,cur; ll ans = 0; string subtask; int tc = 1; ll binpow(ll x,ll y){ if( y == 0 ) return 1; ll res = binpow(x,y/2); res *= res; res %= mod; if( y % 2 ) res *= x; return res%mod; } void solve(){ cin>>n>>k; ll a[n]; ll m = n-k+1; for(int i = 0 ; i < m ; i++){ cin>>a[i]; } int v[n+5]; for(int i = 0 ; i < n ; i++) v[i] = 2; for(int i = m-1 ; i >= 0 ; i--){ if( a[i] == a[i+1]-1 ) { if( v[i] == 1 ){ cout<<0<<"\n"; break; } v[i] = 0; v[i+k] = 1; } else if( a[i] == a[i+1]+1 ) { if( v[i] == 0 ){ cout<<0<<"\n"; break; } v[i] = 1; v[i+k] = 0; } else if( a[i] == a[i+1] ){ v[i+k] = v[i]; } else if( abs(a[i]-a[i+1]) > 1 ){ cout<<0<<"\n"; return; } } ll c1 = 0,c0 = 0; for(int i = 0 ; i < k ; i++){ if( v[i] == 1 ) c1++; else if( v[i] == 0 ) c0++; } ll x = k-(c1+c0); if( x < 0 || a[0]-c1 < 0 || x-(a[0]-c1) < 0 ){ cout<<0<<"\n"; return; } ll fact[k+5]; fact[0] = fact[1] = 1; for(ll i = 2 ; i <= x ; i++){ fact[i] = fact[i-1]*i; fact[i] %= mod; } ans = fact[x]; ll foo = (fact[x-(a[0]-c1)]*fact[a[0]-c1])%mod; ans *= binpow(foo,mod-2); cout<<ans%mod<<"\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; //cin>>T; for(int i = 0 ; i < T ; i++){ //cout<<"Case #"<<i+1<<": "; solve(); tc++; } return 0; } /* same val different variable swapped multidimentional size out of bound for loop (constraint change in loop) forget to change bool to int misread -> missed subtask you thought u declared it huh? not i but x logical operator wrong example/proof thoroughly wrong variables thinking it wrong bruh just try some test case capitals ;-; wrong data structure lol count memory usement corner case oversized array orders statements size initializer while con map -> array wrong digits?? swapped variables?? check if theres any variabled that got declared twice find some pattern name collision constraints??! mod !! resets */
#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...