結果

問題 No.2727 Tetrahedron Game
ユーザー Rubikun
提出日時 2024-04-12 22:35:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,105 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 199,892 KB
最終ジャッジ日時 2025-02-21 00:32:55
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=10005,INF=15<<26;

int dp[MAX][606];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        ll N,K;cin>>N>>K;
        vector<vector<ll>> A(3,vector<ll>(3));
        for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin>>A[i][j];
        ll ans=A[0][0]*A[1][1]*A[2][2]+A[0][1]*A[1][2]*A[2][0]+A[0][2]*A[1][0]*A[2][1];
        ans-=A[0][0]*A[1][2]*A[2][1]+A[0][1]*A[1][0]*A[2][2]+A[0][2]*A[1][1]*A[2][0];
        ans=abs(ans);
        //cout<<ans<<endl;
        vector<ll> B(N);
        for(int i=0;i<N;i++){
            cin>>B[i];B[i]++;
        }
        string S;cin>>S;
        if(ans==0) cout<<"D\n";
        else{
            ans%=606;
            for(int i=0;i<=N;i++) for(int j=0;j<606;j++) dp[i][j]=0;
            for(int i=0;i<606;i++){
                if(i%6==0){
                    if(i/6>=K) dp[N][i]=1;
                    else dp[N][i]=-1;
                }
            }
            for(ll i=N-1;i>=0;i--){
                if(S[i]=='K'){
                    for(ll j=0;j<606;j++){
                        dp[i][j]=-1;
                        chmax(dp[i][j],dp[i+1][j]);
                        chmax(dp[i][j],dp[i+1][(j*B[i])%606]);
                    }
                }else{
                    for(ll j=0;j<606;j++){
                        dp[i][j]=1;
                        chmin(dp[i][j],dp[i+1][j]);
                        chmin(dp[i][j],dp[i+1][(j*B[i])%606]);
                    }
                }
            }
            if(dp[0][ans]==1) cout<<"K\n";
            else if(dp[0][ans]==0) cout<<"D\n";
            else cout<<"P\n";
        }
    }
}

0