結果

問題 No.2727 Tetrahedron Game
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-04-17 10:14:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 197,364 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 10:14:55
合計ジャッジ時間 3,637 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 74 ms
5,376 KB
testcase_02 AC 24 ms
5,376 KB
testcase_03 AC 18 ms
5,376 KB
testcase_04 AC 18 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 19 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 19 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int L = 606;
void solve() {
	int N, K;
	cin >> N >> K;
	int now; ll r;
	{
		ll pnow[3][3];
		for (int i = 0; i < 3; i ++) {
			for (int j = 0; j < 3; j ++) {
				cin >> pnow[i][j];
			}
		}
		r = 0;
		for (int i = 1; i < 3; i ++) {
			for (int ofs = 0; ofs < 3; ofs ++) {
				ll kj = 1;
				for (int j = 0; j < 3; j ++) {
					kj *= pnow[j][(ofs + i * j) % 3];
				}
				r += kj * (i & 1 ? 1ll : -1ll);
			}
		}
		now = abs(r) % L;
	}
	std::vector<int> A(N); string s;
	for (auto& a : A) cin >> a;
	cin >> s;
	int dp[L];
	for (int i = 0; i < L; i ++) {
		if (i % 6) {
			dp[i] = 0;
		} else {
			dp[i] = (((i / 6) % 101) >= K ? 1 : -1);
		}
	}
	for (int i = N - 1; i >= 0; i --) {
		int dp2[L];
		for (int p = 0; p < L; p ++) {
			int x = dp[p], y = dp[(p * (A[i] + 1)) % L];
			dp2[p] = (s[i] == 'K' ? max(x, y) : min(x, y));
		}
		for (int i = 0; i < L; i ++) dp[i] = dp2[i];
	}
			if (r == 0) {
			puts("D");
			return;
			
		}
	cout << (dp[now] == -1 ? "P" : (dp[now] ? "K" : "D")) << endl;
}
int main () {
	int T;
	cin >> T;
	while (T--) solve();
}
0