QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314221 | #7894. Many Many Heads | haze | WA | 3ms | 3724kb | C++23 | 1.3kb | 2024-01-25 14:35:53 | 2024-01-25 14:35:53 |
Judging History
answer
/*
Author: Haze
2024/1/24
*/
#include <bits/stdc++.h>
#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;
inline ll read() {
ll s = 0;
bool fl = false;
char ch = (char) getchar();
while (!isdigit(ch)) {
if (ch == '-')fl = true;
ch = (char) getchar();
}
while (isdigit(ch)) {
s = s * 10 + (ch ^ 48);
ch = (char) getchar();
}
return fl ? -s : s;
}
const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 500099;
bool solve() {
string s;
cin >> s;
int n = s.length();
vector<int>a(n);
char ch = s[0];
for(int i = 0; i < n; ++i, ch = s[i]){
if(ch == '(' || ch == ')')a[i] = 1;
else a[i] = 0;
}
bool fl[2] = {0, 0};
irep(i, 0, n - 2){
if(a[i] == a[i + 1]){
if(fl[a[i]])return false;
fl[a[i]] = 1;
}
if(a[i] == a[i + 1] && i + 2 < n && a[i] == a[i + 2])return false;
}
return true;
}
int main() {
IOS
int T;
cin >> T;
while (T--) {
if(!solve())cout << "No\n";
else cout << "Yes\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3724kb
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: 3520kb
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: 3ms
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]