結果

問題 No.2727 Tetrahedron Game
ユーザー KudeKude
提出日時 2024-04-12 22:37:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,190 bytes
コンパイル時間 4,119 ms
コンパイル使用メモリ 301,492 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-12 22:38:00
合計ジャッジ時間 5,044 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 30 ms
6,944 KB
testcase_02 AC 16 ms
6,940 KB
testcase_03 AC 15 ms
6,944 KB
testcase_04 AC 15 ms
6,940 KB
testcase_05 AC 14 ms
6,948 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 15 ms
6,940 KB
testcase_08 AC 15 ms
6,944 KB
testcase_09 AC 15 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int dp[2][2][101], ndp[2][2][101];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    ll p[3][3]{};
    rep(i, 3) rep(j, 3) cin >> p[i][j];
    VI a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;
    rep(x, 2) rep(y, 2) rep(z, 101) dp[x][y][z] = x || y ? 0 : z >= k ? 1 : -1;
    rrep(i, n) {
      if (s[i] == 'K') {
        rep(x, 2) rep(y, 2) {
          int v = a[i] + 1;
          int px = x, py = y;
          if (px && v % 2 == 0) v /= 2, px = 0;
          if (py && v % 3 == 0) v /= 3, py = 0;
          rep(z, 101) ndp[x][y][z] = max(dp[x][y][z], dp[px][py][(z * v) % 101]);
        }
      } else {
        rep(x, 2) rep(y, 2) {
          int v = a[i] + 1;
          int px = x, py = y;
          if (px && v % 2 == 0) v /= 2, px = 0;
          if (py && v % 3 == 0) v /= 3, py = 0;
          rep(z, 101) ndp[x][y][z] = min(dp[x][y][z], dp[px][py][(z * v) % 101]);
        }
      }
      swap(dp, ndp);
    }
    ll v = 
      p[0][0] * p[1][1] * p[2][2] +
      p[0][1] * p[1][2] * p[2][0] +
      p[0][2] * p[1][0] * p[2][1] -
      p[0][0] * p[1][2] * p[2][1] -
      p[0][1] * p[1][0] * p[2][2] -
      p[0][2] * p[1][1] * p[2][0];
    int x = 1, y = 1;
    if (v % 2 == 0) v /= 2, x = 0;
    if (v % 3 == 0) v /= 3, y = 0;
    v = abs(v);
    int ans = dp[x][y][v % 101];
    cout << (v == 0 || ans == 0 ? 'D' : "PK"[ans > 0]) << '\n';
  }
}
0