QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656727#7683. Hard Brackets Problemtest_algthWA 20ms3772kbC++14884b2024-10-19 13:37:122024-10-19 13:37:15

Judging History

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

  • [2024-10-19 13:37:15]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3772kb
  • [2024-10-19 13:37:12]
  • 提交

answer

#include <bits/stdc++.h>

const int MAXN = 1.01E6;
char A[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--) {
    std::cin >> A;
    bool ok = true;
    std::vector <char> Ans;

    int now = 0, N = strlen(A), e = 0;
    for (int i = 0; i < N; ++i) {
      char a = A[i];
      if (a == '(') {
        if (e && now > 0) Ans.push_back(')');
        Ans.push_back('('), ++now, e = 0;
      }
      else {
        if (!now) Ans.push_back(')');
        now = std::max(0, now - 1);
        e = 1;
      }
      // printf("(%d, %d)\n", i, now);
    }

    if (now == 0) {
      for (char a : Ans)
        std::cout << a;
      std::cout << '\n';
    } else {
      std::cout << "impossible" << '\n';
    }
  }

  return 0;
}

詳細信息

Test #1:

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

input:

3
((()))
(
)))()

output:

(((
impossible
)))(

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 3544kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
(()())
)((((
impossible
((()()
impossible
)())()))
impossible
impossible
(((()(
(()(()
()(()(
(((())
impossible
impossible
(((()(
())())(
(((()(
impossible
())(()
(()(()
()(((
impossible
(()(()
impossible
impossible
impossible
impossible
impossible
()(()(
impossible
impossible
impossible
...

result:

wrong answer the result string is incorrect (test case 2)