QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709309#7894. Many Many HeadsMIS_T__WA 0ms3608kbC++231.7kb2024-11-04 13:55:382024-11-04 13:55:39

Judging History

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

  • [2024-11-04 13:55:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-04 13:55:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
    string s;
    cin >> s;
    // 1 2 3//
    int n = s.size();
    int opt = 0;
    int cnt = 0;
    vector<int>use;
    for ( int i = 0 ; i < n ; i++ ) {
        if ( s[i] == '(' || s[i] == ')' ) {
            if ( opt == 0 ) {
                cnt++;
            } else {
                if ( cnt != 0 ) use.emplace_back(cnt);
                opt = 0;
                cnt = 1;
            }
        } else {
            if ( opt == 1 ) {
                cnt++;
            } else {
                if ( cnt != 0 ) use.emplace_back(cnt);
                opt = 1;
                cnt = 1;
            }
        }
    }
    if ( cnt ) use.emplace_back(cnt);
    // for ( auto i : use ) {
    //     cout << i << ' ';
    // }
    // cout << '\n';
    for ( auto i : use ) {
        if ( i >= 3 ) {
            cout << "No\n";
            return;
        } 
    }
    int num1 = 0, num2 = 0;
    for ( int i = 0 ; i < use.size() ; i++ ) {
        if ( use[i] == 1 ) {
            i += 2;
            while ( use[i] != 1 ) {
                i += 2;
            }
        } else {
            if ( i%2 == 0 ) num1++;
            else num2++;
        }
    }
    for ( int i = 0 ; i < use.size() ; i++ ) {
        if ( i+2 < use.size() ) {
            if ( use[i] + use[i+1] + use[i+2] == 6 ) {
                cout << "No\n";
                return;
            }
        }
    }
    if ( num1 > 1 || num2 > 1 ) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

}
int main() {
    int T = 1;
    cin >> T;
    while ( T-- ) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

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: 3608kb

input:

2
(([([[([
]]))])]])]

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]