結果
| 問題 |
No.2168 双頭ヒドラゲーム
|
| コンテスト | |
| ユーザー |
hotman78
|
| 提出日時 | 2022-12-22 20:27:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,393 bytes |
| コンパイル時間 | 3,039 ms |
| コンパイル使用メモリ | 217,436 KB |
| 最終ジャッジ日時 | 2025-02-09 18:24:57 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 8 |
ソースコード
#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;
}
// void print(string s=""){
// for(auto e:v){
// cerr<<s+"-"<<endl;
// e.print(s+" ");
// }
// }
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) = (exp(Σa))(Σexp(b))
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){
if(b==0){
ch[right]=string_to_tree(s.substr(idx,idx2-idx+1),1)+move(ch[right]);
}else if(right==0){
ch[right]=string_to_tree(s.substr(idx,idx2-idx+1),1)+move(ch[right]);
}else{
ch[right]=string_to_tree(s.substr(idx,idx2-idx+1),1)+move(ch[right]);
}
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;
}
hotman78