QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277359 | #7894. Many Many Heads | SSH# | WA | 1ms | 3792kb | C++20 | 1.2kb | 2023-12-06 17:59:44 | 2023-12-06 17:59:44 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve();
signed main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
bool judge(string s) {
stack<char> st;
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] == '(') {
st.push(s[i]);
} else if (s[i] == ')') {
if (!(st.size() && st.top() == '(')) {
return false;
}
st.pop();
} else if (s[i] == '[') {
st.push(s[i]);
} else {
if (!(st.size() && st.top() == '[')) {
return false;
}
st.pop();
}
}
if (st.size())return false;
return true;
}
void solve() {
string s;
cin >> s;
int n = s.size();
if (n >= 24) {
cout << "No\n";
return;
}
int ans = 0;
for (int i = 0; i < (1ll << n); i++) {
string ss = s;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
if (s[j] == '(' || s[j] == ')') ss[j] = '(';
else ss[j] = '[';
} else {
if (s[j] == '(' || s[j] == ')') ss[j] = ')';
else ss[j] = ']';
}
}
if (judge(ss)) {
cout << ss << "\n";
ans++;
}
}
if (ans == 1) {
cout << "Yes\n";
} else cout << "No\n";
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3792kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
() Yes (()) ()() No [()] Yes (([()])) ()[()]() No ([()]) Yes ([[()]]) ([]()[]) ([])([]) No
result:
wrong output format YES or NO expected, but () found [1st token]