QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215681 | #5108. Prehistoric Programs | YYYYYYYY | RE | 0ms | 0kb | C++14 | 1.3kb | 2023-10-15 12:45:02 | 2023-10-15 12:45:03 |
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 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...