QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215681#5108. Prehistoric ProgramsYYYYYYYYRE 0ms0kbC++141.3kb2023-10-15 12:45:022023-10-15 12:45:03

Judging History

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

  • [2023-10-15 12:45:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-15 12:45:02]
  • 提交

answer

#include <iostream>
#include <string>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    
    std::vector<std::vector<int>> in(n, std::vector<int>(3, 0));

    for (int i = 0; i < n; i++) {
        std::string parentheses;
        std::cin >> parentheses;
        in[i][2] = i + 1;

        int open_count = 0;
        int close_count = 0;

        for (char ch : parentheses) {
            if (ch == '(') {
                open_count++;
            } else if (ch == ')') {
                if (open_count > 0) {
                    open_count--;
                } else {
                    close_count++;
                }
            }
        }

        in[i][0] = open_count;
        in[i][1] = close_count;
    }

    std::vector<int> output;
    int open_count = 0;

    for (int i = 0; i < n; i++) {
        if (in[i][0] == 0 && in[i][1] == 0) {
            output.push_back(in[i][2]);
        } else if (in[i][0] == 0) {
            open_count += in[i][1];
        } else {
            output.insert(output.begin() + open_count, in[i][2]);
        }
    }

    if (open_count == 0) {
        for (int i : output) {
            std::cout << i << " ";
        }
    } else {
        std::cout << "impossible";
    }

    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:


result: