結果
| 問題 |
No.685 Logical Operations
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-01 21:33:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 860 bytes |
| コンパイル時間 | 265 ms |
| コンパイル使用メモリ | 82,128 KB |
| 実行使用メモリ | 75,040 KB |
| 最終ジャッジ日時 | 2024-11-28 13:42:09 |
| 合計ジャッジ時間 | 2,269 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
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)