This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
for(int i = 0 ; i < k ; i++){
cin>>a[i];
}
int v[k];
v[k-1] = 2;
for(int i = 0 ; i < k-1 ; i++){
if( a[i] == a[i+1]+1 ) v[i] = 1;
else if( a[i] == a[i+1]-1 ) v[i] = 0;
else if( a[i] == a[i+1] ) v[i] = 2;
else {
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 ){
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |