QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626964#7894. Many Many Headsadivse#WA 0ms3600kbC++203.0kb2024-10-10 14:15:092024-10-10 14:15:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 14:15:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2024-10-10 14:15:09]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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]