QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626964 | #7894. Many Many Heads | adivse# | WA | 0ms | 3600kb | C++20 | 3.0kb | 2024-10-10 14:15:09 | 2024-10-10 14:15:10 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename... Args>
void bubu(Args... args) { cout << ":: "; ((cout << args << " "), ...); cout << endl; }
void bubu(vector<int> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
using PII = pair<int, int>;
using i128 = __int128;
//=======================================================================
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
//=======================================================================
int fan(char x) {
// if (x == ' ') return 2;
if (x == ')' || x == '(') return 1;
return 0;
}
int st[N];
int top;
signed main() {
kuaidu();
cin >> T;
while (T--) {
string s; cin >> s;
n = s.size();
s = ' ' + s;
// s = s + ' ';
int fl = 1;
if (fan(s[1]) == fan(s[n])) {
if (s[1] == '(' || s[1] == ')') fl = 0;//0找[],1找()
else fl = 1;
}
else {
int l1, l2;
top = 0;
st[++top] = 1;
rep(i, 2, n) {
if (top and st[top] != 1 and fan(s[st[top]]) == fan(s[i])) top--;
else st[++top] = i;
}
l1 = st[top];
top = 0;
st[++top] = n;
rep2(i, n - 1, 1) {
if (top and st[top] != n and fan(s[st[top]]) == fan(s[i])) top--;
else st[++top] = i;
}
l2 = n - st[top] + 1;
// cout << l1 << " " << l2 << endl;
if (l1 > l2) {
if (s[1] == '(' || s[1] == ')') fl = 1; else fl = 0;
}
else {
if (s[n] == '(' || s[n] == ')') fl = 1; else fl = 0;
}
}
// if (s[1] == '(' || s[1] == ')') fl = 0;//0找[],1找()
int i = 1, j = n;
int flag = 1;
while (i < j) {
int lasi = i, lasj = j;
// if (lasi != 0 and lasj != n + 1) {
while (fan(s[i]) != fl) i++;
while (fan(s[j]) != fl) j--;
// }
// else i = 1, j = n;
if (i > j) {
int len = lasj - lasi + 1;
if (len >= 4) flag = 0;
break;
}
int len = i - lasi + (lasj - j);
if (len >= 4) { flag = 0; break; }
fl = 1 - fl;
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: -100
Wrong Answer
time: 0ms
memory: 3600kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]