結果
| 問題 |
No.2168 双頭ヒドラゲーム
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-12-20 01:40:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,572 bytes |
| コンパイル時間 | 2,446 ms |
| コンパイル使用メモリ | 189,760 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-18 01:42:54 |
| 合計ジャッジ時間 | 3,339 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 4 |
コンパイルメッセージ
main.cpp: In function 'int comp(std::string, std::string)':
main.cpp:134:1: warning: control reaches end of non-void function [-Wreturn-type]
134 | }
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
string advance(string &S, int &p){
int cnt = 0;
string ans;
while (true){
ans += S[p];
if (S[p] == '('){
cnt++;
}
if (S[p] == ')'){
cnt--;
}
p++;
if (cnt == 0 && S[p] != '('){
break;
}
}
return ans;
}
tuple<string, string, string> parse(string S){
int p = 1;
string s1;
if (S[p] == '('){
s1 = advance(S, p);
}
p++;
string s2;
if (S[p] == '('){
s2 = advance(S, p);
}
p++;
string s3 = S.substr(p);
return make_tuple(s1, s2, s3);
}
int comp(string S, string T){
if (S == "" && T == ""){
return 0;
}
if (S == ""){
return -1;
}
if (T == ""){
return 1;
}
vector<string> s;
while (true){
string S1, S2, S3;
tie(S1, S2, S3) = parse(S);
s.push_back("(" + S1 + "|" + S2 + ")");
if (S3 == ""){
break;
}
S = S3;
}
vector<string> t;
while (true){
string T1, T2, T3;
tie(T1, T2, T3) = parse(T);
t.push_back("(" + T1 + "|" + T2 + ")");
if (T3 == ""){
break;
}
T = T3;
}
int N = s.size();
int M = t.size();
vector<string> s2;
s2.push_back(s[0]);
for (int i = 1; i < N; i++){
while (!s2.empty()){
if (comp(s2.back(), s[i]) == -1){
s2.pop_back();
} else {
break;
}
}
s2.push_back(s[i]);
}
vector<string> t2;
t2.push_back(t[0]);
for (int i = 1; i < M; i++){
while (!t2.empty()){
if (comp(t2.back(), t[i]) == -1){
t2.pop_back();
} else {
break;
}
}
t2.push_back(t[i]);
}
N = s2.size();
M = t2.size();
if (N == 1 && M == 1){
string S1 = get<0>(parse(s2[0]));
string S2 = get<1>(parse(s2[0]));
string T1 = get<0>(parse(t2[0]));
string T2 = get<1>(parse(t2[0]));
int p = comp(S1, T1);
if (p == 0){
return comp(S2, T2);
}
if (p == -1){
int r = comp(S2, t2[0]);
if (r == 0){
return -1;
} else {
return r;
}
}
if (p == 1){
int r = comp(s2[0], T2);
if (r == 0){
return 1;
} else {
return r;
}
}
} else {
s2.push_back("");
t2.push_back("");
int p = 0;
while (true){
int r = comp(s2[p], t2[p]);
if (r != 0){
return r;
}
if (s2[p] == "" && t2[p] == ""){
return 0;
}
p++;
}
}
}
int main(){
string T1;
cin >> T1;
string T2;
cin >> T2;
int ans = comp(T1, T2);
if (ans == 1){
cout << 0 << endl;
} else {
cout << 1 << endl;
}
}
SSRS