Submission #71170804


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
struct State{
    int len,link;
    int next[26];
};
const int MAXN = 200005;
State st[MAXN * 2];
int sz,last;
int memo[MAXN * 2];
void sam_init(){
    st[0].len = 0;
    st[0].link = -1;
    memset(st[0].next,-1,sizeof(st[0].next));
    sz = 1;
    last = 0;
}
void sam(char c){
    int cur = sz++;
    st[cur].len = st[last].len + 1;
    memset(st[cur].next,-1,sizeof(st[cur].next));
    int p = last;
    int code = c - 'a';
    while(p != -1 && st[p].next[code] == -1){
        st[p].next[code] = cur;
        p = st[p].link;
    }
    if(p == -1){
        st[cur].link = 0;
    }
    else{
        int q = st[p].next[code];
        if(st[p].len + 1 == st[q].len){
            st[cur].link = q;
        }
        else{
            int clone = sz++;
            st[clone].len = st[p].len + 1;
            memcpy(st[clone].next,st[q].next,sizeof(st[q].next));
            st[clone].link = st[q].link;
            while(p != -1 && st[p].next[code] == q){
                st[p].next[code] = clone;
                p = st[p].link;
            }
            st[q].link = st[cur].link = clone;
        }
    }
    last = cur;
}

int game(int u){
    if(memo[u] != -1) return memo[u];
    bool cfo = false;
    for(int i=0;i<26;i++){
        if(st[u].next[i] != -1){
            if(game(st[u].next[i]) == 0){
                cfo = true;
                break;
            }
        }
    }
    return memo[u] = (cfo ? 1 : 0);
}

void solve(){
    string s;
    cin>>s;
    sam_init();
    for(char c : s){
        sam(c);
        //cout<<c<<endl;
    }
    for(int i=0;i<sz;i++) memo[i] = -1;
    if(game(0))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Submission Info

Submission Time
Task G - Substring Game
User Luongdung
Language C++23 (GCC 15.2.0)
Score 600
Code Size 1950 Byte
Status AC
Exec Time 72 ms
Memory 55292 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 32
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 3600 KiB
01_small_00.txt AC 13 ms 3600 KiB
01_small_01.txt AC 19 ms 3464 KiB
01_small_02.txt AC 24 ms 3624 KiB
02_random_00.txt AC 68 ms 52440 KiB
02_random_01.txt AC 71 ms 54672 KiB
02_random_02.txt AC 69 ms 52792 KiB
02_random_03.txt AC 72 ms 54644 KiB
02_random_04.txt AC 71 ms 55292 KiB
02_random_05.txt AC 65 ms 49356 KiB
02_random_06.txt AC 64 ms 47756 KiB
02_random_07.txt AC 61 ms 47020 KiB
02_random_08.txt AC 45 ms 35756 KiB
02_random_09.txt AC 45 ms 36212 KiB
02_random_10.txt AC 45 ms 38264 KiB
02_random_11.txt AC 46 ms 36484 KiB
02_random_12.txt AC 17 ms 3688 KiB
02_random_13.txt AC 17 ms 3696 KiB
02_random_14.txt AC 17 ms 3808 KiB
02_random_15.txt AC 17 ms 3728 KiB
02_random_16.txt AC 19 ms 7152 KiB
02_random_17.txt AC 19 ms 7236 KiB
02_random_18.txt AC 19 ms 7024 KiB
02_random_19.txt AC 19 ms 7100 KiB
03_handmade_00.txt AC 22 ms 32832 KiB
03_handmade_01.txt AC 22 ms 32804 KiB
03_handmade_02.txt AC 51 ms 37832 KiB
03_handmade_03.txt AC 48 ms 36488 KiB
03_handmade_04.txt AC 1 ms 3752 KiB
03_handmade_05.txt AC 32 ms 47584 KiB
03_handmade_06.txt AC 25 ms 32720 KiB
03_handmade_07.txt AC 23 ms 32664 KiB