結果
| 問題 |
No.2727 Tetrahedron Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-12 22:31:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 2,000 ms |
| コード長 | 1,221 bytes |
| コンパイル時間 | 548 ms |
| コンパイル使用メモリ | 66,756 KB |
| 実行使用メモリ | 27,968 KB |
| 最終ジャッジ日時 | 2024-10-02 23:30:30 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include<iostream>
#include<cassert>
using namespace std;
int A[10101];
string S;
int memo[10001][606];
int N,K;
int dfs(int t,int d)
{
if(t==N)
{
if(d%6!=0)return 0;
else if(d/6>=K)return 1;
else return -1;
}
if(memo[t][d]!=0)
{
return memo[t][d]-2;
}
int x=dfs(t+1,d),y=dfs(t+1,d*(A[t]+1)%606);
if(S[t]=='K')
{
if(x==1||y==1)
{
memo[t][d]=3;
}
else if(x==0||y==0)
{
memo[t][d]=2;
}
else
{
memo[t][d]=1;
}
}
else
{
if(x==-1||y==-1)
{
memo[t][d]=1;
}
else if(x==0||y==0)
{
memo[t][d]=2;
}
else
{
memo[t][d]=3;
}
}
return memo[t][d]-2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;cin>>T;
for(;T--;)
{
cin>>N>>K;
long P[3][3];
for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>P[i][j];
for(int i=0;i<N;i++)cin>>A[i];
cin>>S;
long D=0;
D+=P[0][0]*P[1][1]*P[2][2];
D+=P[0][1]*P[1][2]*P[2][0];
D+=P[0][2]*P[1][0]*P[2][1];
D-=P[0][2]*P[1][1]*P[2][0];
D-=P[0][0]*P[1][2]*P[2][1];
D-=P[0][1]*P[1][0]*P[2][2];
D=abs(D);
if(D==0)
{
cout<<"D\n";
continue;
}
D%=606;
for(int i=0;i<N;i++)for(int j=0;j<606;j++)memo[i][j]=0;
int ret=dfs(0,D);
cout<<(ret==1?"K\n":ret==0?"D\n":"P\n");
}
}