QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559480#6410. Classical DP Problemmjkim112358RE 9ms10720kbPython3701b2024-09-11 22:20:042024-09-11 22:20:05

Judging History

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

  • [2024-09-11 22:20:05]
  • 评测
  • 测评结果:RE
  • 用时:9ms
  • 内存:10720kb
  • [2024-09-11 22:20:04]
  • 提交

answer

mod=998244353
def solve(li,k):
    if(len(li)==k):return pow(k,k,mod)
    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]=1
        for j in range(1,li[k]+1):
            dp[i][j]=dp[i-1][j]*(j+(li[i-1]-k))+dp[i-1][j-1]*(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=n
for i in range(n-1):
    if(l[i]>=i+1 and l[i+1]<i+1):r=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)

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 10720kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 9ms
memory: 10708kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Dangerous Syscalls

input:

2
1 1

output:


result: