結果

問題 No.2168 双頭ヒドラゲーム
ユーザー hotman78hotman78
提出日時 2022-12-22 20:49:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 3,964 ms
コンパイル使用メモリ 222,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 11:21:16
合計ジャッジ時間 4,857 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(n) (n).begin(),(n).end()


struct tree{
    vector<pair<tree,tree>>v;
    tree(){}
    tree(const vector<pair<tree,tree>>&v):v(v){};
    tree operator+(const tree& b)const{
        tree res;
        for(auto c:v){
            if(!b.v.empty()&&c<b.v[0])break;
            res.v.emplace_back(c);
        }
        for(auto c:b.v){
            res.v.emplace_back(c);
        }
        sort(res.v.begin(),res.v.end());
        reverse(res.v.begin(),res.v.end());
        return res;
    }
    bool operator==(const tree&b)const{
        return v==b.v;
    }
    friend bool operator<(const pair<tree,tree>&a,const pair<tree,tree>&b){
        if(a.first==b.first)return a.second<b.second;
        else if(a.first<b.first)return a.second<tree(vector{b});
        else return tree(vector{a})<b.second;
    }
    bool operator<(const tree&b)const{
        return v<b.v;
    }
};

// (a|b)c = φ(a,b)+c

tree string_to_tree(string s,bool b=0){
    if(s=="")return tree();
    assert(s[0]=='(');
    int idx=1,idx2=1,val=0;
    tree ch[2]={};
    bool right=0;
    while(1){
        if(val==0&&s[idx2]=='|'){
            right=1;
            idx=idx2+1;
            idx2=idx;
            continue;
        }
        if(s[idx2]=='(')val++;
        if(val==0&&s[idx2]==')'){
            break;
        }
        if(s[idx2]==')')val--;
        if(val==0){
            ch[right]=move(ch[right])+string_to_tree(s.substr(idx,idx2-idx+1),1);
            idx=idx2+1;
        }
        idx2++;
    }
    if(b==0){
        return ch[1];
    }else{
        auto res=tree(vector{make_pair(ch[0],ch[1])});
        return res;
    }
}
int main(){
    string s;
    string t;
    cin>>s>>t;
    s="(|"+s+")";
    t="(|"+t+")";
    auto ts=string_to_tree(s);
    auto tt=string_to_tree(t);
    // ts.print();
    // tt.print();
    cout<<(tt<ts?0:1)<<endl;
}
0