Submission #71158970
Source Code Expand
/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#include <unordered_map>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define int long long
using namespace std;
inline int read();
void write(int);
void writeln(int);
int T;
string S;
struct SAM {
struct D {
int nxt[26], lk, len;
D() : lk(-1), len(0) { fill(nxt, nxt + 26, -1); }
};
vector <D> st;
int lst;
explicit SAM(int mxl = 0) {
st.reserve(2 * mxl + 5); st.pb(D());
st[0].lk = -1, st[0].len = 0, lst = 0;
}
void extend(int c) {
int now = st.size();
st.pb(D()), st[now].len = st[lst].len + 1;
int pre = lst;
while(pre != -1 && st[pre].nxt[c] == -1) st[pre].nxt[c] = now, pre = st[pre].lk;
if(pre == -1) st[now].lk = 0;
else {
int suf = st[pre].nxt[c];
if(st[pre].len + 1 == st[suf].len) st[now].lk = suf;
else {
int sz = st.size();
st.pb(st[suf]), st[sz].len = st[pre].len + 1;
while(pre != -1 && st[pre].nxt[c] == suf) st[pre].nxt[c] = sz, pre = st[pre].lk;
st[suf].lk = st[now].lk = sz;
}
}
lst = now;
}
};
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while(T--) {
cin >> S;
int n = S.size(), SZ;
SAM hz(n);
for(int i = 0; i < n; i++) hz.extend(S[i] - 'a');
SZ = hz.st.size();
int mxl = 0;
for(int i = 0; i < SZ; i++) mxl = max(mxl, hz.st[i].len);
vector <int> cnt(mxl + 1, 0), ord(SZ);
for(int i = 0; i < SZ; i++) cnt[hz.st[i].len]++;
for(int i = 1; i <= mxl; i++) cnt[i] += cnt[i - 1];
for(int i = SZ - 1; i >= 0; i--) ord[--cnt[hz.st[i].len]] = i;
vector <bool> dp(SZ, 0);
for(int i = SZ - 1; i >= 0; i--) {
int u = ord[i]; bool ww = 0;
for(int j = 0; j < 26; j++) {
int v = hz.st[u].nxt[j];
if(v != -1) if(!dp[v]) { ww = 1; break; }
}
dp[u] = ww;
}
puts(dp[0] ? "Alice" : "Bob");
}
// printf("\nThe time used: ");
// printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
inline int read() {
int res = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
while(ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
return res * f;
}
void write(int x) {
static int sta[35];
int top = 0;
do { sta[top++] = x % 10, x /= 10; } while(x);
while(top) putchar(sta[--top] ^ 48);
}
void writeln(int x) {
write(x);
putchar('\n');
}
Submission Info
| Submission Time |
|
| Task |
G - Substring Game |
| User |
WZwangchongming |
| Language |
C++23 (GCC 15.2.0) |
| Score |
600 |
| Code Size |
2790 Byte |
| Status |
AC |
| Exec Time |
138 ms |
| Memory |
95864 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3728 KiB |
| 01_small_00.txt |
AC |
12 ms |
3716 KiB |
| 01_small_01.txt |
AC |
15 ms |
3532 KiB |
| 01_small_02.txt |
AC |
21 ms |
3564 KiB |
| 02_random_00.txt |
AC |
137 ms |
95864 KiB |
| 02_random_01.txt |
AC |
138 ms |
95800 KiB |
| 02_random_02.txt |
AC |
136 ms |
95764 KiB |
| 02_random_03.txt |
AC |
138 ms |
95680 KiB |
| 02_random_04.txt |
AC |
137 ms |
95800 KiB |
| 02_random_05.txt |
AC |
124 ms |
83896 KiB |
| 02_random_06.txt |
AC |
123 ms |
84128 KiB |
| 02_random_07.txt |
AC |
129 ms |
83896 KiB |
| 02_random_08.txt |
AC |
97 ms |
62156 KiB |
| 02_random_09.txt |
AC |
93 ms |
62284 KiB |
| 02_random_10.txt |
AC |
90 ms |
62272 KiB |
| 02_random_11.txt |
AC |
94 ms |
62268 KiB |
| 02_random_12.txt |
AC |
21 ms |
3940 KiB |
| 02_random_13.txt |
AC |
21 ms |
3972 KiB |
| 02_random_14.txt |
AC |
21 ms |
3780 KiB |
| 02_random_15.txt |
AC |
21 ms |
3844 KiB |
| 02_random_16.txt |
AC |
34 ms |
12968 KiB |
| 02_random_17.txt |
AC |
35 ms |
12176 KiB |
| 02_random_18.txt |
AC |
39 ms |
14724 KiB |
| 02_random_19.txt |
AC |
33 ms |
11488 KiB |
| 03_handmade_00.txt |
AC |
51 ms |
50492 KiB |
| 03_handmade_01.txt |
AC |
52 ms |
50380 KiB |
| 03_handmade_02.txt |
AC |
90 ms |
62752 KiB |
| 03_handmade_03.txt |
AC |
88 ms |
62752 KiB |
| 03_handmade_04.txt |
AC |
1 ms |
3712 KiB |
| 03_handmade_05.txt |
AC |
73 ms |
80184 KiB |
| 03_handmade_06.txt |
AC |
52 ms |
50500 KiB |
| 03_handmade_07.txt |
AC |
50 ms |
50500 KiB |