結果

問題 No.269 見栄っ張りの募金活動
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-29 09:52:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 1,595 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 91,688 KB
最終ジャッジ日時 2023-09-08 00:10:23
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,360 KB
testcase_01 AC 70 ms
71,604 KB
testcase_02 AC 70 ms
71,388 KB
testcase_03 AC 75 ms
75,568 KB
testcase_04 AC 100 ms
81,568 KB
testcase_05 AC 72 ms
75,560 KB
testcase_06 AC 70 ms
71,276 KB
testcase_07 AC 149 ms
91,688 KB
testcase_08 AC 70 ms
71,316 KB
testcase_09 AC 70 ms
71,124 KB
testcase_10 AC 69 ms
71,576 KB
testcase_11 AC 78 ms
75,876 KB
testcase_12 AC 69 ms
71,360 KB
testcase_13 AC 81 ms
75,756 KB
testcase_14 AC 76 ms
76,324 KB
testcase_15 AC 80 ms
75,816 KB
testcase_16 AC 70 ms
71,308 KB
testcase_17 AC 70 ms
71,584 KB
testcase_18 AC 96 ms
75,788 KB
testcase_19 AC 81 ms
75,536 KB
testcase_20 AC 76 ms
75,904 KB
testcase_21 AC 76 ms
75,908 KB
testcase_22 AC 78 ms
75,792 KB
testcase_23 AC 75 ms
75,948 KB
testcase_24 AC 77 ms
75,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
2<=n<=100
0<=s<=20000
0<=k<=100

i+1人目以降の見え張り分k円はi人目の時に募金するとする。
0-indexed
0人目のi円はi*n+k*(n-1)円の価値がある
j人目のi円はi*(n-j)+k*(n-1-j)円の価値がある
n-1人目のi円はi円の価値

kの倍数部分を抜いて考える
合計でt=s-k*n*(n-1)//2円の募金をする。
募金する人は前の募金者以上の円を募金しないといけない。
0人目のi円はi*n円の価値がある
j人目のi円はi*(n-j)円の価値がある
n-1人目のi円はi円の価値

j人目の人は(n-j)の倍数の遷移ができる
dp[u]->ndp[u+v*(n-j)] 
または
dp[u-v*(n-j)]->ndp[u] 0<=v
u以下で(n-j)で割ったあまりが同じ数値から遷移
%(n-j)で分類して累積和遷移
"""
def main0(n,s,k):
  mod=10**9+7
  t=s-k*n*(n-1)//2
  if t<0:return 0
  mod=10**9+7
  dp=[0]*(t+1)
  dp[0]=1
  # dp[i]:i円にする場合数
  for j in range(n):
    ndp=[0]*(t+1)
    for i in range(0,t+1):
      # j人目がi円募金する場合
      val=i*(n-j) 
      if val>t:break
      for u in range(t-val+1):
        ndp[u+val]+=dp[u]
        ndp[u+val]%=mod
    dp=ndp
  return dp[t]

def main1(n,s,k):
  mod=10**9+7
  t=s-k*n*(n-1)//2
  if t<0:return 0
  mod=10**9+7
  dp=[0]*(t+1)
  dp[0]=1
  # dp[i]:i円にする場合数
  for j in range(n):
    ndp=[0]*(t+1)
    ary=[0]*(n-j)
    for u in range(t+1):
      ary[u%(n-j)]+=dp[u]
      ary[u%(n-j)]%=mod
      ndp[u]+=ary[u%(n-j)]
    dp=ndp
  return dp[t]

if __name__=='__main__':
  n,s,k=map(int,input().split())
  ret1=main1(n,s,k)
  print(ret1)
  
0