QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694220#7894. Many Many Headstest_algth#WA 4ms3628kbC++141.6kb2024-10-31 17:30:052024-10-31 17:30:05

Judging History

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

  • [2024-10-31 17:30:05]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3628kb
  • [2024-10-31 17:30:05]
  • 提交

answer

#include <bits/stdc++.h>

const int MAXN = 1.01E5;
char A[MAXN];
int B[MAXN], C[MAXN];

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);

  int testCase = 1;
  std::cin >> testCase;
  while (testCase--) {
    int N;
    std::cin >> (A + 1);
    N = strlen(A + 1);

    int cnts[2] = {0, 0};
    bool flag = true;

    std::vector <int> pos;
    pos.push_back(0);
    B[0] = C[0] = 0;
    for (int i = 1; i <= N; ++i) {
      B[i] = C[i] = 0;
      if (A[i] == '(' || A[i] == ')') {
        cnts[1] = 0;
        ++cnts[0];
      } else {
        cnts[0] = 0;
        ++cnts[1];
      }

      if (cnts[0] == 2 || cnts[1] == 2) {
        pos.push_back(i);
      }

      if (cnts[0] > 2 || cnts[1] > 2) {
        flag = false;
      }
    }

    if (flag == false) {
      std::cout << "No\n";
    } else {
      int pre = 0;
      cnts[0] = cnts[1] = 0;

      flag = false;
      for (int i = 1; i < pos.size(); ++i) {
        int sum = pos[i] - pos[i - 1] - 2 - pre;
        pre = pos[i] - pos[i - 1] - 2;
        // printf("(%d)\n", pos[i]);
        int j = i;
        while (j + 1 < pos.size() && pos[j + 1] == pos[j] + 2) ++j;
        if (j >= i + 1 || sum < 0) {
          flag = true;
          break;
        }

        // if (!sum) {
          if (A[pos[i]] == '(' || A[pos[i]] == ')') {++C[sum]; flag |= C[sum] > 1; }
          else { ++B[sum]; flag |= B[sum] > 1; }
        // }
      }

      if (cnts[1] > 1 || cnts[0] > 1 || flag) {
        std::cout << "No\n";
      } else {
        std::cout << "Yes\n";
      }
    }
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 4ms
memory: 3604kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No...

result:

wrong answer expected YES, found NO [3rd token]