結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-19 02:58:23 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 992 bytes |
| 記録 | |
| コンパイル時間 | 3,446 ms |
| コンパイル使用メモリ | 335,924 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-19 02:59:09 |
| 合計ジャッジ時間 | 43,618 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(void){
int q;
cin>>q;
stack<char>st;
int flag=-1,r1=0,r2=0,r3=0;
while(q--){
int op;
cin>>op;
if(op==1){
char c;
cin>>c;
st.push(c);
if(c=='('){
r1++;
}else if(c=='|'){
if(!st.empty()&&st.top()=='|'&&flag==-1)flag=st.size()+1;
r2++;
}else{
r3++;
}
if(flag==-1){
if(r1<r2||r2<r3){
flag=st.size();
}
}
}else{
if(st.top()=='('){
r1--;
}else if(st.top()=='|'){
r2--;
}else{
r3--;
}
st.pop();
if(flag!=-1&&st.size()<flag)flag=-1;
}
cout<<flag<<" ";
cout<<(flag==-1&&r1==r2&&r2==r3?"Yes":"No")<<endl;
}
return 0;
}