QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559498#6410. Classical DP Problemmjkim112358WA 8ms10712kbPython3826b2024-09-11 22:32:582024-09-11 22:32:58

Judging History

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

  • [2024-09-11 22:32:58]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:10712kb
  • [2024-09-11 22:32:58]
  • 提交

answer

mod=998244353
def solve(li,k):
    if(len(li)==k):
        ret=1
        for i in li:ret*=i;ret%=mod
        return ret
    dp=[[0]*(li[k]+1) for i in range(k+1)]
    dp[0][0]=1
    for i in range(1,k+1):
        dp[i][0]=dp[i-1][0]*((li[i-1]-li[k]))
        dp[i][0]%=mod
        for j in range(1,li[k]+1):
            dp[i][j]=dp[i-1][j]*(j+(li[i-1]-li[k]))+dp[i-1][j-1]*(li[k]-(j-1))
            dp[i][j]%=mod
    return dp[k][li[k]]
n=int(input())
l=list(map(int,input().split()))[::-1]+[0]
#l의 차를 구한 수열
l2=[l[i]-l[i+1] for i in range(n)]
l3=[]
for i in range(n):l3+=[n-i]*l2[n-i-1]
r=l[0]
print(l)
for i in range(n):
    if(l[i]>=i+1):r=i+1
    if(l[i]<i+1):break
ans1=solve(l[:-1],r)
ans2=solve(l3,r)
f=1
for i in range(1,r+1):
    f*=i
    f%=mod
print(r,(ans1+ans2-f)%mod)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 10712kb

input:

3
1 2 3

output:

[3, 2, 1, 0]
2 6

result:

wrong output format Expected integer, but "[3," found