結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー qumazakiqumazaki
提出日時 2020-07-04 04:11:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 72,828 KB
最終ジャッジ日時 2023-10-17 11:08:00
合計ジャッジ時間 9,371 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
64,328 KB
testcase_01 AC 51 ms
64,328 KB
testcase_02 AC 52 ms
64,328 KB
testcase_03 AC 56 ms
66,408 KB
testcase_04 AC 60 ms
68,576 KB
testcase_05 AC 49 ms
64,328 KB
testcase_06 AC 49 ms
64,328 KB
testcase_07 AC 50 ms
64,328 KB
testcase_08 AC 50 ms
64,328 KB
testcase_09 AC 54 ms
66,388 KB
testcase_10 AC 56 ms
66,408 KB
testcase_11 AC 60 ms
68,584 KB
testcase_12 AC 61 ms
68,604 KB
testcase_13 AC 65 ms
70,660 KB
testcase_14 AC 64 ms
70,688 KB
testcase_15 AC 65 ms
70,660 KB
testcase_16 AC 63 ms
68,608 KB
testcase_17 AC 62 ms
68,608 KB
testcase_18 AC 62 ms
68,608 KB
testcase_19 AC 64 ms
68,608 KB
testcase_20 AC 67 ms
70,668 KB
testcase_21 AC 63 ms
68,608 KB
testcase_22 AC 62 ms
68,572 KB
testcase_23 AC 62 ms
68,556 KB
testcase_24 AC 59 ms
68,548 KB
testcase_25 AC 63 ms
70,632 KB
testcase_26 AC 63 ms
70,632 KB
testcase_27 AC 66 ms
70,692 KB
testcase_28 AC 62 ms
68,576 KB
testcase_29 AC 57 ms
68,560 KB
testcase_30 AC 59 ms
68,572 KB
testcase_31 AC 57 ms
66,500 KB
testcase_32 AC 64 ms
70,632 KB
testcase_33 AC 64 ms
70,632 KB
testcase_34 AC 65 ms
70,632 KB
testcase_35 AC 64 ms
70,632 KB
testcase_36 AC 61 ms
68,576 KB
testcase_37 AC 65 ms
70,668 KB
testcase_38 AC 59 ms
68,580 KB
testcase_39 AC 58 ms
68,560 KB
testcase_40 AC 65 ms
70,632 KB
testcase_41 AC 58 ms
68,560 KB
testcase_42 AC 58 ms
68,560 KB
testcase_43 AC 58 ms
68,560 KB
testcase_44 AC 57 ms
68,560 KB
testcase_45 AC 58 ms
68,560 KB
testcase_46 AC 63 ms
70,624 KB
testcase_47 AC 60 ms
68,560 KB
testcase_48 AC 65 ms
70,660 KB
testcase_49 AC 69 ms
72,828 KB
testcase_50 AC 58 ms
68,544 KB
testcase_51 AC 52 ms
66,424 KB
testcase_52 AC 59 ms
68,548 KB
testcase_53 AC 63 ms
70,632 KB
testcase_54 AC 59 ms
68,580 KB
testcase_55 AC 62 ms
70,624 KB
testcase_56 AC 62 ms
70,632 KB
testcase_57 AC 63 ms
70,624 KB
testcase_58 AC 63 ms
70,624 KB
testcase_59 AC 56 ms
68,548 KB
testcase_60 AC 63 ms
70,632 KB
testcase_61 AC 63 ms
70,632 KB
testcase_62 AC 58 ms
68,548 KB
testcase_63 AC 57 ms
68,560 KB
testcase_64 AC 62 ms
68,576 KB
testcase_65 AC 60 ms
68,544 KB
testcase_66 AC 59 ms
68,580 KB
testcase_67 AC 62 ms
70,648 KB
testcase_68 AC 63 ms
70,624 KB
testcase_69 AC 61 ms
70,624 KB
testcase_70 AC 64 ms
70,624 KB
testcase_71 AC 63 ms
70,624 KB
testcase_72 AC 61 ms
68,588 KB
testcase_73 AC 64 ms
70,632 KB
testcase_74 AC 60 ms
68,580 KB
testcase_75 AC 57 ms
66,500 KB
testcase_76 AC 63 ms
68,576 KB
testcase_77 AC 62 ms
68,576 KB
testcase_78 AC 62 ms
68,576 KB
testcase_79 AC 62 ms
68,576 KB
testcase_80 AC 62 ms
68,576 KB
testcase_81 AC 61 ms
68,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
m = 27

base = [2] * m
lim_up = [2] * m
# lim_down = [2] * m
x = n
for i in range(m):
    x += 2
    lim_up[i] = x%5
    # lim_down[i] = 4 - lim_up[i]
    x //= 5

lim_up = lim_up[::-1]

# dp[i][j] *= i桁目まで見て、各桁の合計数がjのやつの個数
dp_0 = [[0]*(m*4+1) for _ in range(m+1)]
dp = [[0]*(m*4+1) for _ in range(m+1)]
dp_lim = [[0]*(m*4+1) for _ in range(m+1)]

dp_0[0][0] = 1
dp_lim[0][0] = 1

phase = 0
for i in range(1,m+1):
    dp_0[i][i*2] = 1
    lim_j = sum(lim_up[:i])
    dp_lim[i][lim_j] = 1
    if(lim_j != i*2)&(phase==0):
        phase = 1

    for j in range(m*4+1):
        dp[i][j] = sum(dp[i-1][max(0,j-4):j+1])
        if(phase==1):
            for k in range(3,lim_up[i-1]):
                dp[i][j] += dp_lim[i-1][j-k]
        elif(phase==2):
            for k in range(lim_up[i-1]):
                dp[i][j] += dp_lim[i-1][j-k]
            for k in range(3,5):
                dp[i][j] += dp_0[i-1][j-k]

    if(lim_j != i*2)&(phase==1):
        phase = 2

ans = dp[i][2*m] + dp_lim[i][2*m]
print(ans)
0