QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314003#7894. Many Many HeadsJWRuixiWA 5ms6048kbC++171.3kb2024-01-25 11:10:092024-01-25 11:10:10

Judging History

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

  • [2024-01-25 11:10:10]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6048kb
  • [2024-01-25 11:10:09]
  • 提交

answer

#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
using namespace std;

using vi = vector<int>;
using cint = const int;

using pii = pair<int, int>;
#define fi first
#define se second

constexpr int N = 1e5 + 9;
int n, m, a[N], stk[N], top;
char s[N];
vi v[N];

void slv () {
  cin >> (s + 1);
  n = strlen(s + 1);
  L (i, 1, n) {
    switch (s[i]) {
      case '(' : a[i] = 1; break;
      case ')' : a[i] = 1; break;
      case '[' : a[i] = 2; break;
      case ']' : a[i] = 2; break;
    }
  }
  top = m = 0;
  L (i, 1, n) {
    if (!top) {
      v[++m] = {a[i]};
      stk[++top] = a[i];
    } else {
      if (stk[top] ^ a[i]) {
        stk[++top] = a[i];
        v[m].eb(a[i]);
      } else {
        --top;
      }
    }
  }
  if (m > 2) {
    cout << "No\n";
    return;
  }
  if (m == 2 && v[1][0] == v[2][0]) {
    cout << "No\n";
    return;
  }
  L (i, 1, m) {
    L (j, 0, (int)v[i].size() - 2) {
      if (v[i][j] == v[i][j + 1]) {
        cout << "No\n";
        return;
      }
    }
  }
  cout << "Yes\n";
}

int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) slv();
}
// I love WHQ!

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5980kb

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

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: 5ms
memory: 6048kb

input:

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

output:

Yes
Yes
Yes
Yes
Yes
Yes
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
Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No...

result:

wrong answer expected NO, found YES [45th token]