結果
| 問題 | No.2727 Tetrahedron Game |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-12 23:11:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 302 ms / 2,000 ms |
| コード長 | 1,568 bytes |
| コンパイル時間 | 145 ms |
| コンパイル使用メモリ | 82,224 KB |
| 実行使用メモリ | 77,720 KB |
| 最終ジャッジ日時 | 2024-10-02 23:45:30 |
| 合計ジャッジ時間 | 2,462 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
from collections import deque
def solve():
N,K = list(map(int,input().split()))
p11, p12, p13 = list(map(int,input().split()))
p21, p22, p23 = list(map(int,input().split()))
p31, p32, p33 = list(map(int,input().split()))
A = list(map(int,input().split()))
S = input()
V6 = p11 * p22 * p33 + p12*p23*p31 + p13*p21*p32 - p11*p23*p32 - p12*p21*p33 - p13*p22*p31
V6 = abs(V6)
if V6 == 0:
print("D")
return
DP = [0]*606
for i in range(606):
if i%6 == 0:
if i//6 >= K:
DP[i] = 1
else:
DP[i] = 2
for i in range(N-1,-1,-1):
a = A[i]
DP1 = [0]*606
if S[i] == "K":
for j in range(606):
nxt1 = j
nxt2 = j * (1+a) % 606
if DP[nxt1] == 1 or DP[nxt2] == 1:
DP1[j] = 1
elif DP[nxt1] == 2 and DP[nxt2] == 2:
DP1[j] = 2
else:
DP1[j] = 0
else:
for j in range(606):
nxt1 = j
nxt2 = j * (1+a) % 606
if DP[nxt1] == 2 or DP[nxt2] == 2:
DP1[j] = 2
elif DP[nxt1] == 1 and DP[nxt2] == 1:
DP1[j] = 1
else:
DP1[j] = 0
DP = DP1
#print(V6)
#print(DP)
if DP[V6%606] == 1:
print("K")
elif DP[V6%606] == 2:
print("P")
else:
print("D")
T = int(input())
for i in range(T):
solve()