QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214947 | #5108. Prehistoric Programs | dereto | WA | 15ms | 4028kb | C++14 | 900b | 2023-10-15 01:41:06 | 2023-10-15 01:41:06 |
Judging History
answer
#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
string str;
vector<tuple<int, int, int>> arr(n, tuple<int, int, int>(0, 0, 0));
for(int i=0;i<n;i++){
cin >> str;
get<2>(arr[i]) = i + 1;
for(int j=0;j<str.length();j++){
if(str[j]=='('){
get<1>(arr[i]) += 1;
}else{
get<1>(arr[i]) -= 1;
}
get<0>(arr[i]) = std::min(get<0>(arr[i]), get<1>(arr[i]));
}
get<1>(arr[i]) -= get<0>(arr[i]);
}
sort(arr.begin(), arr.end(), greater<tuple<int, int, int>>());
int sum = 0;
int min = 0;
for(int i=0;i<n;i++){
min = std::min(min, sum - get<0>(arr[i]));
sum += get<1>(arr[i]) + get<0>(arr[i]);
}
if(sum != 0 || min < 0) {
cout << "impossible";
return 0;
}
for(int i=0;i<n;i++){
cout << get<2>(arr[i]) << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 4028kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
41248 4238 13809 27609 5338 48374 2458 389 48749 6754 42979 18533 14096 6986 32583 31692 23456 5803 3405 169 43508 38930 34539 26695 26677 10427 9225 46429 46194 41740 39743 35132 30771 25061 24373 21764 11398 2253 45491 35039 34110 33777 31402 23312 5699 41641 41639 39389 35743 28794 23551 9790 736...
result:
ok good plan
Test #2:
score: 0
Accepted
time: 2ms
memory: 3860kb
input:
1000 ( ))(())) ((((())())))((())(()))( )( ) ))) ))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()()) )((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))( )))((( ( )))()()()))) ( (((())(((...
output:
36 13 66 386 966 585 286 257 127 83 39 595 476 907 814 598 329 214 981 427 62 707 662 384 131 807 793 511 869 767 638 449 379 271 80 746 632 474 422 387 327 239 20 989 975 919 915 715 553 535 502 473 345 334 296 171 168 88 31 947 945 929 881 872 863 859 852 827 820 819 799 778 774 738 731 725 686 66...
result:
ok good plan
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
2 () ()
output:
2 1
result:
ok good plan
Test #4:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
2 (( ))
output:
1 2
result:
ok good plan
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
2 )( ()
output:
2 1
result:
wrong answer wrong plan (expected impossible)