結果

問題 No.3342 AAB Game
コンテスト
ユーザー Rubikun
提出日時 2025-11-13 22:55:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 206,636 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-13 22:55:15
合計ジャッジ時間 3,542 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

map<string,bool> MA;

bool solve(string S){
    if(MA.count(S)) return MA[S];
    for(int i=0;i<si(S);i++){
        for(int j=i;j<si(S);j++){
            string T=S.substr(i,j-i+1);
            if(T.back()!='B') continue;
            bool ok=true;
            for(int a=0;a<si(T)-1;a++){
                if(T[a]!='A') ok=false;
            }
            if(!ok) continue;
            
            string X=S;
            for(int a=0;a<si(T)-1;a++){
                X[i+a]='B';
            }
            X[j]='A';
            if(!solve(X)) return MA[S]=true;
        }
    }
    return MA[S]=false;
}

bool esper(string S){
    int x=0;
    for(char c:S){
        x*=2;
        if(c=='B') x++;
        x%=3;
    }
    return x;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    if(esper(S)) cout<<"Alice\n";
    else cout<<"Bob\n";
    return 0;
    
    
    for(int n=1;n<=10;n++){
        int cn=0;
        for(int bit=0;bit<(1<<n);bit++){
            string S;
            for(int i=0;i<n;i++){
                if(bit&(1<<i)) S+='A';
                else S+='B';
            }
            assert(solve(S)==esper(S));
            cout<<solve(S)<<" "<<esper(S)<<endl;
            if(solve(S)) cn++;
        }
        cout<<cn<<endl;
    }
}


0