Submission #36628168
Source Code Expand
#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 16;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int n, all;
string s[N];
bool dp[1 << N][N];
signed main()
{
n = read(), all = (1 << n) - 1;
for(re int i = 0; i < n; i++) cin >> s[i];
for(re int i = all - 1; i >= 1; i--){
for(re int j = 0; j < n; j++){ //枚举上一轮最后选的是啥
if(!(i >> j & 1)) continue;
for(re int k = 0; k < n; k++){ //枚举这一轮选啥
if(i >> k & 1 || s[j].back() != s[k][0]) continue;
dp[i][j] |= (!dp[i | (1 << k)][k]); //只要走到一个必败态就是必胜态
}
}
}
bool flag = false;
for(re int i = 0; i < n; i++) flag |= (!dp[1 << i][i]);
if(flag) puts("First");
else puts("Second");
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Shiritori |
| User | Booksnow |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1246 Byte |
| Status | AC |
| Exec Time | 44 ms |
| Memory | 4588 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:29:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
29 | for(re int i = 0; i < n; i++) cin >> s[i];
| ^
./Main.cpp:30:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
30 | for(re int i = all - 1; i >= 1; i--){
| ^
./Main.cpp:31:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
31 | for(re int j = 0; j < n; j++){ //枚举上一轮最后选的是啥
| ^
./Main.cpp:33:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
33 | for(re int k = 0; k < n; k++){ //枚举这一轮选啥
| ^
./Main.cpp:40:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
40 | for(re int i = 0; i < n; i++) flag |= (!dp[1 << i][i]);
| ^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_a_to_a_15.txt, 02_a_to_a_16.txt, 02_a_to_a_17.txt, 02_a_to_a_18.txt, 03_max_19.txt, 03_max_20.txt, 03_max_21.txt, 03_max_22.txt, 03_max_23.txt, 03_max_24.txt, 03_max_25.txt, 03_max_26.txt, 03_max_27.txt, 03_max_28.txt, 03_max_29.txt, 03_max_30.txt, 03_max_31.txt, 03_max_32.txt, 04_loop_33.txt, 04_loop_34.txt, 04_loop_35.txt, 05_gote_jiro_36.txt, 05_gote_jiro_37.txt, 05_gote_jiro_38.txt, 05_gote_jiro_39.txt, 05_gote_jiro_40.txt, 05_gote_jiro_41.txt, 05_gote_jiro_42.txt, 05_gote_jiro_43.txt, 05_gote_jiro_44.txt, 05_gote_jiro_45.txt, 05_gote_jiro_46.txt, 05_gote_jiro_47.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 6 ms | 3484 KiB |
| 00_sample_01.txt | AC | 2 ms | 3488 KiB |
| 00_sample_02.txt | AC | 42 ms | 4508 KiB |
| 01_random_03.txt | AC | 2 ms | 3472 KiB |
| 01_random_04.txt | AC | 2 ms | 3568 KiB |
| 01_random_05.txt | AC | 3 ms | 3528 KiB |
| 01_random_06.txt | AC | 26 ms | 3996 KiB |
| 01_random_07.txt | AC | 19 ms | 3884 KiB |
| 01_random_08.txt | AC | 36 ms | 4512 KiB |
| 01_random_09.txt | AC | 38 ms | 4416 KiB |
| 01_random_10.txt | AC | 2 ms | 3480 KiB |
| 01_random_11.txt | AC | 21 ms | 3896 KiB |
| 01_random_12.txt | AC | 19 ms | 4020 KiB |
| 01_random_13.txt | AC | 34 ms | 4400 KiB |
| 01_random_14.txt | AC | 37 ms | 4480 KiB |
| 02_a_to_a_15.txt | AC | 20 ms | 3892 KiB |
| 02_a_to_a_16.txt | AC | 39 ms | 4504 KiB |
| 02_a_to_a_17.txt | AC | 19 ms | 3996 KiB |
| 02_a_to_a_18.txt | AC | 38 ms | 4392 KiB |
| 03_max_19.txt | AC | 41 ms | 4588 KiB |
| 03_max_20.txt | AC | 39 ms | 4512 KiB |
| 03_max_21.txt | AC | 39 ms | 4404 KiB |
| 03_max_22.txt | AC | 43 ms | 4392 KiB |
| 03_max_23.txt | AC | 41 ms | 4528 KiB |
| 03_max_24.txt | AC | 38 ms | 4504 KiB |
| 03_max_25.txt | AC | 39 ms | 4448 KiB |
| 03_max_26.txt | AC | 37 ms | 4508 KiB |
| 03_max_27.txt | AC | 37 ms | 4444 KiB |
| 03_max_28.txt | AC | 38 ms | 4496 KiB |
| 03_max_29.txt | AC | 37 ms | 4528 KiB |
| 03_max_30.txt | AC | 36 ms | 4412 KiB |
| 03_max_31.txt | AC | 36 ms | 3488 KiB |
| 03_max_32.txt | AC | 37 ms | 3508 KiB |
| 04_loop_33.txt | AC | 12 ms | 3624 KiB |
| 04_loop_34.txt | AC | 21 ms | 3820 KiB |
| 04_loop_35.txt | AC | 42 ms | 4488 KiB |
| 05_gote_jiro_36.txt | AC | 44 ms | 4448 KiB |
| 05_gote_jiro_37.txt | AC | 2 ms | 3524 KiB |
| 05_gote_jiro_38.txt | AC | 3 ms | 3488 KiB |
| 05_gote_jiro_39.txt | AC | 4 ms | 3572 KiB |
| 05_gote_jiro_40.txt | AC | 41 ms | 4588 KiB |
| 05_gote_jiro_41.txt | AC | 43 ms | 4388 KiB |
| 05_gote_jiro_42.txt | AC | 11 ms | 3648 KiB |
| 05_gote_jiro_43.txt | AC | 5 ms | 3572 KiB |
| 05_gote_jiro_44.txt | AC | 2 ms | 3392 KiB |
| 05_gote_jiro_45.txt | AC | 17 ms | 3788 KiB |
| 05_gote_jiro_46.txt | AC | 43 ms | 4512 KiB |
| 05_gote_jiro_47.txt | AC | 42 ms | 4388 KiB |