QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#316284 | #7894. Many Many Heads | Kotomi | WA | 6ms | 3608kb | C++20 | 866b | 2024-01-27 19:17:54 | 2024-01-27 19:17:55 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
bool solve() {
string s;
cin >> s;
unordered_map<char, int> kind;
kind['('] = kind[')'] = 1;
kind['['] = kind[']'] = 2;
int n = s.size();
int cnt1 = 0;
int cnt2 = 0;
for (int i = 0, j = i; i < n; ++ i) {
while (j < n && kind[s[i]] == kind[s[j]]) ++ j;
int len = j - i;
if (len >= 3) return false;
if (len == 2) {
if (kind[s[i]] == 1) cnt1 ++;
else cnt2 ++;
if (cnt1 >= 2 || cnt2 >= 2) return false;
}
i = j - 1;
}
return true;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T; cin >> T;
while (T --) {
cout << (solve() ? "Yes": "No") << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes No Yes No
result:
ok 6 token(s): yes count is 3, no count is 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 3584kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes No No Yes No No Yes No No No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [7th token]