提出 #71162736


ソースコード 拡げる

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
*/
/*
  Credits -
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
  Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
  https://codeforces.com/contest/4/submission/150120627
*/
#include <atcoder/string>
#include <atcoder/segtree>

#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
    #pragma GCC target ("sse,sse2,mmx")
    #pragma GCC optimize ("-ffloat-store")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define dbg(args...) 42;
    #define endl "\n"
#endif

// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second

using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.

// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

const lli INF = 1e7;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}


int OP(int a, int b) { return min(a, b); }
int E() { return INF; }

bool solve(string &s){
    const lli n=sz(s);
    const auto sa = atcoder::suffix_array(s);
    const auto lcp = atcoder::lcp_array(s, sa);
    atcoder::segtree<int, OP, E> seg(lcp);
    map<lli,bool> dp;
    // dbg(s);
    // for(const auto &i:sa){
    //     dbg(s.substr(i));
    // }
    auto re=y_combinator([&](const auto &self,const lli L,const lli R,const bool f)->bool{
        // dbg(L,R,f);
        if(L>R)
            return !f;
        if(L==R){
            const lli len = n-sa[L];
            // dbg(L,sa[L],len,f,(len+f)&1);
            return (len+f)&1;
        }
        auto isSuf=[&](const lli i,const lli l)->lli{
            return sa[i]+l==n;
        };
        const lli key = L*n*2+R*2+f;
        if(dp.count(key))
            return dp[key];
        const lli len = seg.prod(L,R);
        // dbg(L,R,len);
        auto getNext=[&](const lli i,const char c)->lli{
            auto chk=[&](const lli j)->bool{
                if(j>=n)
                    return false;
                const lli p=sa[j];
                assert(p+len<n);
                if(s[p+len]>c)
                    return false;
                // if(p+len<n&&s[p+len]>c)
                //     return false;
                return true;
            };
            if(!chk(i))
                return i;
            lli l=i,r=R+1;
            while(r-l>1){
                const lli m=(l+r)/2;
                if(chk(m))
                    l=m;
                else
                    r=m;
            }
            return r;
        };

        lli i=L;
        if(isSuf(i,len))
            i++;
        const lli nxt = (len+1)&1;
        // dbg(L,R,nxt,i);
        for(char c='a';c<='z';c++){
            const lli j=getNext(i,c);
            // if(L==0&&R==3){
            //     dbg(L,R,i,j,c);
            // }
            if(i==j)
                continue;
            const auto res=self(i,j-1,nxt);
            // dbg(f,nxt,L,R,c,i,j-1,res);
            if(!res)
                return dp[key]=true;
            i=j;
        }
        return dp[key]=false;
    });

    return re(0,n-1,0);
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
lli T=1;
cin>>T;
while(T--)
{
    string s;
    cin>>s;
    const auto res=solve(s);
    cout<<(res?"Alice":"Bob")<<endl;
}   aryanc403();
    return 0;
}

提出情報

提出日時
問題 G - Substring Game
ユーザ aryanc403
言語 C++23 (GCC 15.2.0)
得点 0
コード長 5932 Byte
結果 RE
実行時間 153 ms
メモリ 51052 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 600
結果
AC × 1
AC × 15
WA × 3
RE × 14
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3716 KiB
01_small_00.txt RE 99 ms 3552 KiB
01_small_01.txt RE 96 ms 3608 KiB
01_small_02.txt RE 97 ms 3500 KiB
02_random_00.txt RE 135 ms 9564 KiB
02_random_01.txt RE 115 ms 9728 KiB
02_random_02.txt WA 40 ms 9332 KiB
02_random_03.txt RE 115 ms 9696 KiB
02_random_04.txt RE 116 ms 9744 KiB
02_random_05.txt AC 38 ms 10256 KiB
02_random_06.txt RE 119 ms 9584 KiB
02_random_07.txt RE 132 ms 10184 KiB
02_random_08.txt AC 36 ms 11032 KiB
02_random_09.txt AC 35 ms 9616 KiB
02_random_10.txt AC 35 ms 9604 KiB
02_random_11.txt AC 35 ms 10964 KiB
02_random_12.txt RE 97 ms 3752 KiB
02_random_13.txt RE 99 ms 3628 KiB
02_random_14.txt RE 95 ms 3856 KiB
02_random_15.txt RE 96 ms 3828 KiB
02_random_16.txt AC 29 ms 4732 KiB
02_random_17.txt AC 29 ms 4488 KiB
02_random_18.txt AC 28 ms 4748 KiB
02_random_19.txt AC 28 ms 4652 KiB
03_handmade_00.txt WA 153 ms 51036 KiB
03_handmade_01.txt WA 150 ms 51052 KiB
03_handmade_02.txt AC 27 ms 10448 KiB
03_handmade_03.txt AC 27 ms 9764 KiB
03_handmade_04.txt AC 2 ms 3920 KiB
03_handmade_05.txt AC 59 ms 34928 KiB
03_handmade_06.txt AC 88 ms 35556 KiB
03_handmade_07.txt RE 104 ms 10572 KiB