QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212962 | #6346. Record Parity | happypotato | WA | 23ms | 50744kb | C++14 | 1.2kb | 2023-10-13 23:54:22 | 2023-10-13 23:54:22 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
using pii=pair <int,int>;
using tii=pair <pii,int>;
using rii=pair <int,pii>;
using qii=pair <pii,pii>;
const int mod=998244353LL;
int f[2000010],inv[2000010],finv[2000010];
void init(){
f[0]=f[1]=inv[0]=inv[1]=finv[0]=finv[1]=1;
for (int i=2; i<2000010; i++){
f[i]=f[i-1]*i%mod;
inv[i]=inv[mod%i]*(mod-mod/i)%mod;
finv[i]=finv[i-1]*inv[i]%mod;
}
}
int ncr(int n,int r){
if (n<r) return 0;
return f[n]*finv[n-r]%mod*finv[r]%mod;
}
void solve(){
int n,k;
cin>>n>>k;
int p[n+1];
for (int i=1; i<=n; i++) cin>>p[i];
vector <int> v;
v.pb(1);
for (int i=2; i<=n; i++){
if (p[i-1]>p[i]) v.pb(1);
else v.back()++;
}
int ans=0;
for (int i:v){
ans+=ncr(i,k);
ans%=mod;
}
if (k&1) ans=(mod-ans)%mod;
cout<<ans<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>>t;
init();
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 50460kb
input:
5 2 4 1 2 5 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 17ms
memory: 50744kb
input:
7 3 1 2 3 4 5 6 7
output:
998244318
result:
ok 1 number(s): "998244318"
Test #3:
score: 0
Accepted
time: 22ms
memory: 50524kb
input:
5 5 2 5 4 1 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 23ms
memory: 50440kb
input:
10 3 9 7 3 6 10 4 8 2 5 1
output:
998244352
result:
wrong answer 1st numbers differ - expected: '0', found: '998244352'