結果

問題 No.2727 Tetrahedron Game
ユーザー MasKoaTSMasKoaTS
提出日時 2024-01-02 18:14:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 2,236 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 216,080 KB
実行使用メモリ 59,008 KB
最終ジャッジ日時 2024-01-02 18:14:39
合計ジャッジ時間 4,880 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 298 ms
6,676 KB
testcase_02 AC 164 ms
6,676 KB
testcase_03 AC 192 ms
59,008 KB
testcase_04 AC 195 ms
59,008 KB
testcase_05 AC 172 ms
23,808 KB
testcase_06 AC 181 ms
28,544 KB
testcase_07 AC 140 ms
13,784 KB
testcase_08 AC 170 ms
23,808 KB
testcase_09 AC 180 ms
23,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define MOD 101
using namespace std;
using ll = long long;


ll powmod(ll a, ll n) {
    ll ret = 1;
    while(n){
        if(n & 1){
            ret *= a;
            ret %= MOD;
        }
        n >>= 1;
        a *= a;
        a %= MOD;
    }
    return ret;
}
const ll INV6 = powmod(6, MOD - 2);


ll det(vector<vector<ll> >& P){
    ll ret = 0;
    for(int i = 0; i < 3; ++i){
        ret += P[i][0] * P[(i + 1) % 3][1] * P[(i + 2) % 3][2];
        ret -= P[i][2] * P[(i + 1) % 3][1] * P[(i + 2) % 3][0];
    }
    return ret;
}


char solve(int N, int K, vector<vector<ll> >& P, vector<int>& a, string& s){
    ll d = abs(det(P));
    if(d == 0){
        return 'D';
    }
    vector<vector<vector<int> > > dp(N + 1, vector<vector<int> >(MOD, vector<int>(4, -1)));
    for(int j = 0; j < MOD; ++j){
        dp[N][j][3] = (j >= K) ? 1 : 0;
    }
    for(int i = N - 1; i >= 0; --i){
        vector<int> stat_next = (s[i] == 'K') ? vector<int>({1, -1, 0}) : vector<int>({0, -1, 1});
        int val = a[i] + 1;
        bool val_div2 = (val % 2 == 0), val_div3 = (val % 3 == 0);
        for(int j = 0; j < MOD; ++j){
            for(int k = 0; k < 4; ++k){
                vector<int> results = { dp[i + 1][j][k], dp[i + 1][j * val % MOD][k | val_div2 | (val_div3 << 1)] };
                for(auto& x : stat_next){
                    if(find(all(results), x) == results.end()){
                        continue;
                    }
                    dp[i][j][k] = x;
                    break;
                }
            }
        }
    }
    bool div2 = (d % 2 == 0), div3 = (d % 3 == 0);
    int stat_init = dp[0][d % MOD * INV6 % MOD][div2 | (div3 << 1)];
    if(stat_init == -1){
        return 'D';
    }
    return (stat_init == 1) ? 'K' : 'P';
}


int main(){
    int t;  cin >> t;

    for(int i = 0; i < t; ++i){
        int N, K;  cin >> N >> K;
        vector<vector<ll> > P(3, vector<ll>(3));
        for(auto& v : P){
            cin >> v[0] >> v[1] >> v[2];
        }
        vector<int> a(N);
        for(auto& x : a){
            cin >> x;
        }
        string s;  cin >> s;
        cout << solve(N, K, P, a, s) << endl;
    }

    return 0;
}
0