結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-27 19:45:29 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,202 ms / 2,000 ms |
| コード長 | 1,078 bytes |
| 記録 | |
| コンパイル時間 | 4,216 ms |
| コンパイル使用メモリ | 339,736 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-17 19:46:37 |
| 合計ジャッジ時間 | 36,469 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int q,t;
char c;
int main(){
cin >> q;
stack<char> st;
stack<bool> history;
while(q--){
cin >> t;
if(t == 1){
cin >> c;
st.push(c);
if(st.size() >= 3){
char a = st.top(); st.pop();
char b = st.top(); st.pop();
char c = st.top(); st.pop();
if(a == ')' && b == '|' && c == '('){
history.push(1);
}
else {
st.push(c);
st.push(b);
st.push(a);
history.push(0);
}
}
else {
history.push(0);
}
}
else{
int last = history.top();
history.pop();
if(last){
st.push('(');
st.push('|');
}
else{
st.pop();
}
}
cout << (st.empty() ? "Yes" : "No") << "\n";
}
}