QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240795#6346. Record Parityylf#WA 11ms21152kbC++141.1kb2023-11-05 19:14:252023-11-05 19:14:26

Judging History

你现在查看的是最新测评结果

  • [2023-11-05 19:14:26]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:21152kb
  • [2023-11-05 19:14:25]
  • 提交

answer

//逆向思维,思考最后答案的形式,考虑枚举
//DP:状态转移与初始状态
//答案<=maxn,然后证明可以取到maxn
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10,mod=998244353;
ll n,k,A[N],fact[N],infact[N];

ll ksm(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b=b>>1;
    }
    return res;
}
ll C(ll a,ll b)
{
    if(a<b) return 0;
    return fact[a]*infact[b]%mod*infact[a-b]%mod;
}
int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);

    fact[0]=infact[0]=1;

    for(ll a=1;a<N;a++) fact[a]=fact[a-1]*a%mod;
    infact[N-1]=ksm(fact[N-1],mod-2);
    for(ll a=N-2;a>=1;a--) infact[a]=infact[a+1]*(a+1)%mod;
    cin>>n>>k;
    for(ll a=1;a<=n;a++) cin>>A[a];
    ll ans=0;

    for(ll i=1;i<=n;i++)
    {
        ll x=A[i],l=i;
        while(i<n&&A[i+1]>A[i]) i++;

        if(k%2==1) ans-=C(i-l+1,k);
        else ans+=C(i-l+1,k);
        ans+=mod;
        ans%=mod;
    }
    cout<<ans;
   
    
    

}

//https://cftracker.netlify.app/contests

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 20320kb

input:

5 2
4 1 2 5 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 11ms
memory: 21076kb

input:

7 3
1 2 3 4 5 6 7

output:

998244318

result:

ok 1 number(s): "998244318"

Test #3:

score: 0
Accepted
time: 7ms
memory: 21052kb

input:

5 5
2 5 4 1 3

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 7ms
memory: 21152kb

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'