結果

問題 No.685 Logical Operations
ユーザー shotoyooshotoyoo
提出日時 2021-09-01 21:33:45
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 77,836 KB
最終ジャッジ日時 2023-08-19 01:19:42
合計ジャッジ時間 4,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
71,488 KB
testcase_01 AC 60 ms
71,432 KB
testcase_02 AC 62 ms
75,056 KB
testcase_03 AC 60 ms
71,432 KB
testcase_04 AC 61 ms
71,392 KB
testcase_05 AC 66 ms
71,164 KB
testcase_06 AC 65 ms
71,324 KB
testcase_07 AC 64 ms
75,052 KB
testcase_08 AC 62 ms
75,292 KB
testcase_09 AC 65 ms
75,840 KB
testcase_10 AC 69 ms
76,704 KB
testcase_11 AC 74 ms
76,724 KB
testcase_12 AC 72 ms
76,340 KB
testcase_13 AC 78 ms
76,756 KB
testcase_14 AC 85 ms
77,836 KB
testcase_15 AC 78 ms
76,772 KB
testcase_16 AC 83 ms
77,312 KB
testcase_17 AC 83 ms
76,824 KB
testcase_18 AC 76 ms
76,692 KB
testcase_19 AC 75 ms
76,416 KB
testcase_20 AC 75 ms
76,348 KB
testcase_21 AC 63 ms
75,440 KB
testcase_22 AC 63 ms
74,980 KB
testcase_23 AC 72 ms
76,708 KB
testcase_24 AC 69 ms
76,244 KB
testcase_25 AC 75 ms
77,036 KB
testcase_26 AC 76 ms
76,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n = int(input())
l = [
    [[0,0,0], [-1, 1, 0]],
    [[1,1,0], [0,-1,1]]
]
dp = {}
M = 10**9+7
def sub(y, v1, v3, v4):
    if y==0:
        return v1 and v3 and v4
    elif y<0:
        return 0
    if (y,v1,v3,v4) in dp:
        return dp[y,v1,v3,v4]
    res = 0
    for i in range(2):
        for j in range(2):
            ll = l[i][j]
            nv1 = v1 + ll[0]
            nv3 = v3 + ll[1]
            nv4 = v4 + ll[2]
            nv1 = max(0, min(1, nv1))
            nv3 = max(0, min(1, nv3))
            nv4 = max(0, min(1, nv4))
            res += sub((y-j)//2, nv1, nv3, nv4)
    dp[y,v1,v3,v4] = res%M
    return res%M
ans = sub(n, 1, 0, 0)
print(ans%M)
0