QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215604 | #5108. Prehistoric Programs | YYYYYYYY | TL | 0ms | 0kb | C++14 | 2.1kb | 2023-10-15 12:05:26 | 2023-10-15 12:05:26 |
answer
#include <iostream>
#include <cstring>
#include<string>
#include <vector>
#include <algorithm>
int main() {
int n = 0;
std::string parentheses;
std::cin >> n;
int sum = 0;
std::vector<std::vector<int>> in(n, std::vector<int>(3, 0));
std::cin.tie(NULL);
for (int i = 0; i < n; i++) {
std::cin >> parentheses;
int par = 0;
in[i][2]=i+1;
while(parentheses[par]!='\0'){
if(parentheses[par]=='('){
in[i][0] += 1;
}
else if(parentheses[par]==')'){
if(in[i][0]>0){
in[i][0] -= 1;
}
else {
in[i][1] += 1;
}
}
par++;
}
sum += in[i][0]-in[i][1];
// std::cout<<in[i][0]<<" "<<in[i][1];
}
if(sum!=0){
std::cout<<"impossible!!"<<sum;
return 0;
}
std::vector<int> v;
std::vector<int> value0;
std::vector<int> value1;
std::vector<int> right;
std::vector<int> left;
int middle = 0;
int cur[2]={0};
int flag = 0;
right.insert(right.begin(),0);
left.insert(left.begin(),0);
for(int i = 0; i < n; i++){
std::sort(in.begin(), in.end(), [](const std::vector<int>& a, const std::vector<int>& b){
int temp1 = (a[0] == a[1] ? 0 : (a[0] > a[1] ? 1 : -1));
int temp2 = (b[0] == b[1] ? 0 : (b[0] > b[1] ? 1 : -1));
//0 if the string has no unpaired '(', 1 if the string has more '(' than ')', -1 otherwise
if (temp1 != temp2) return temp1 > temp2;
//the larger temporary signal should be placed first
if (temp1 == 1) return a[1] < b[1];
//the string with less unpaired ')' should be placed first
else return a[0] > b[0];
//the string with more unpaired '(' should be placed first
});
}
//v[i] = left+v+right
sum = 0;
// std::cout<<"left"<<left[0]<<"right"<<right[0];
for(int i = 0; i < v.size(); i++){
sum -= in[i][1];
if(sum<0){
std::cout<<"impossible";
return 0;
}
sum+=in[i][0];
}
for (int i = 0; i < in.size(); i++) {
std::cout << in[i][2] << " ";
}
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...