結果
問題 | No.2727 Tetrahedron Game |
ユーザー | kotatsugame |
提出日時 | 2024-04-12 22:31:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 1,221 bytes |
コンパイル時間 | 635 ms |
コンパイル使用メモリ | 67,060 KB |
実行使用メモリ | 28,016 KB |
最終ジャッジ日時 | 2024-04-12 22:31:33 |
合計ジャッジ時間 | 2,060 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 15 ms
6,944 KB |
testcase_02 | AC | 28 ms
6,940 KB |
testcase_03 | AC | 56 ms
27,976 KB |
testcase_04 | AC | 36 ms
28,016 KB |
testcase_05 | AC | 121 ms
12,788 KB |
testcase_06 | AC | 112 ms
14,884 KB |
testcase_07 | AC | 105 ms
8,264 KB |
testcase_08 | AC | 124 ms
13,580 KB |
testcase_09 | AC | 122 ms
13,500 KB |
ソースコード
#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"); } }