QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121668#6410. Classical DP ProblemSolitaryDream#WA 1ms3640kbC++201.2kb2023-07-08 17:07:512023-07-08 17:07:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 17:07:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2023-07-08 17:07:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=2e5+1e3+7,P=998244353;

int n,a[N],b[N];

int fac[N],inv[N];

int qpow(int a,int b)
{
    int ret=1;
    while(b)
    {
        if(b&1)
            ret=1ll*ret*a%P;
        b>>=1;
        a=1ll*a*a%P;
    }
    return ret;
}

int k;

int calc(int *a,int x)
{
    int ret=1;
    for(int i=1;i<=k;i++)
        ret=1ll*ret*(a[i]-x)%P;
    return ret;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        b[a[i]]++;
    for(int i=n;i>=1;i--)
        b[i]+=b[i+1];
    k=1;
    for(int i=2;i<=n+1;i++)
        if(a[i]<i||b[i]<i)
        {
            k=i-1;
            break;
        }
    int ans=0;
    fac[0]=1;
    for(int i=1;i<=k;i++)
        fac[i]=1ll*fac[i-1]*i%P;
    inv[k]=qpow(fac[k],P-2);
    for(int i=k-1;i>=0;i--)
        inv[i]=1ll*inv[i+1]*(i+1)%P;
    int t=b[k+1];
    for(int i=0;i<=t;i++)
        ans=(ans+1ll*(i&1?P-1:1)*fac[t]%P*inv[i]%P*inv[t-i]%P*calc(a,i))%P;
    t=a[k+1];
    for(int i=0;i<=t;i++)
        ans=(ans+1ll*(i&1?P-1:1)*fac[t]%P*inv[i]%P*inv[t-i]%P*calc(b,i))%P;
    ans=(ans-fac[k]+P)%P;
    printf("%d %d\n",k,ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3588kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3640kb

input:

2
1 1

output:

1 1

result:

wrong answer 2nd numbers differ - expected: '2', found: '1'