結果

問題 No.2727 Tetrahedron Game
ユーザー RubikunRubikun
提出日時 2024-04-12 22:35:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,105 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 202,688 KB
実行使用メモリ 27,388 KB
最終ジャッジ日時 2024-04-12 22:35:13
合計ジャッジ時間 3,399 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 36 ms
6,816 KB
testcase_02 AC 18 ms
6,944 KB
testcase_03 AC 23 ms
27,364 KB
testcase_04 AC 23 ms
27,388 KB
testcase_05 AC 20 ms
12,596 KB
testcase_06 AC 21 ms
15,188 KB
testcase_07 AC 18 ms
8,424 KB
testcase_08 AC 22 ms
13,508 KB
testcase_09 AC 20 ms
14,032 KB
権限があれば一括ダウンロードができます

ソースコード

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