QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214819 | #5108. Prehistoric Programs | YYYYYYYY | RE | 0ms | 0kb | C++14 | 943b | 2023-10-15 00:16:28 | 2023-10-15 00:16:29 |
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int num;
cin >> num;
vector<vector<int>> v(num);
for(int i = 0; i < num; i++){
v[i][2] = i + 1;
string s;
cin >> s;
int mn = 0, cur = 0;
for(auto x : s){
if(x == '(')cur++;
else cur--;
mn = min(mn, cur);
}
cur -= mn;
v[i][0] = cur;
v[i][1] = -mn;
}
sort(v.begin(), v.end(), [&](const vector<int> &a, const vector<int> &b){
int s1 = (a[0] == a[1] ? 0 : (a[0] > a[1] ? 1 : -1));
int s2 = (b[0] == b[1] ? 0 : (b[0] > b[1] ? 1 : -1));
if (s1 != s2) return s1 > s2;
if (s1 == 1) return a[1] < b[1];
else return a[0] > b[0];
});
int mn = 0, cur = 0;
for(auto x : v){
mn = min(mn, cur - x[1]);
cur += x[0] - x[1];
}
if(mn < 0 || cur != 0)cout << "impossible\n";
else {
for(auto x : v){
cout << x[2] << "\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...