QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559480 | #6410. Classical DP Problem | mjkim112358 | RE | 9ms | 10720kb | Python3 | 701b | 2024-09-11 22:20:04 | 2024-09-11 22:20:05 |
Judging History
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)
Details
Tip: Click on the bar to expand more detailed information
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