結果
問題 | No.2727 Tetrahedron Game |
ユーザー | MasKoaTS |
提出日時 | 2023-09-28 17:45:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 376 ms / 2,000 ms |
コード長 | 1,777 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 79,308 KB |
最終ジャッジ日時 | 2024-09-17 20:52:01 |
合計ジャッジ時間 | 3,897 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
67,132 KB |
testcase_01 | AC | 376 ms
79,308 KB |
testcase_02 | AC | 361 ms
78,484 KB |
testcase_03 | AC | 252 ms
77,060 KB |
testcase_04 | AC | 268 ms
76,908 KB |
testcase_05 | AC | 303 ms
77,848 KB |
testcase_06 | AC | 293 ms
77,668 KB |
testcase_07 | AC | 254 ms
78,088 KB |
testcase_08 | AC | 262 ms
77,388 KB |
testcase_09 | AC | 310 ms
78,120 KB |
ソースコード
import sys input = sys.stdin.readline MOD = 101 INV2, INV3 = pow(2, MOD - 2, MOD), pow(3, MOD - 2, MOD) def det(A): ret = 0 B = A[:] + [A[0]] + [A[1]] for i in range(3): ret += B[i][0] * B[i+1][1] * B[i+2][2] ret -= B[i][2] * B[i+1][1] * B[i+2][0] return ret def solve(N, K, P, a, s): d = abs(det(P)) if(d == 0): return 'D' dp = [[-1] * 4 for _ in [0] * MOD] for j in range(MOD): dp[j][3] = int(j >= K) for i in range(N - 1, -1, -1): ndp = [[-1] * 4 for _ in [0] * MOD] player_is_koa = (s[i] == 'K') val = a[i] + 1 val_div2, val_div3 = (val % 2 == 0), (val % 3 == 0) for j in range(MOD): for k in range(4): results = [dp[j][k], dp[j * val % MOD][k | val_div2 | (val_div3 << 1)]] if(player_is_koa): if(1 in results): ndp[j][k] = 1 elif(-1 in results): ndp[j][k] = -1 else: ndp[j][k] = 0 else: if(0 in results): ndp[j][k] = 0 elif(-1 in results): ndp[j][k] = -1 else: ndp[j][k] = 1 dp = ndp[:] div2, div3 = (d % 2 == 0), (d % 3 == 0) stat_init = dp[d % MOD * INV2 * INV3 % MOD][div2 | (div3 << 1)] if(stat_init == 1): return 'K' elif(stat_init == 0): return 'P' return 'D' t = int(input()) for _ in [0] * t: N, K = map(int, input().split()) P = [list(map(int, input().split())) for _ in [0] * 3] a = list(map(int, input().split())) s = input()[:-1] print(solve(N, K, P, a, s))