QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217612#5108. Prehistoric ProgramsdrldrlsWA 477ms70056kbC++174.5kb2023-10-17 02:36:312023-10-17 02:36:31

Judging History

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

  • [2023-10-17 02:36:31]
  • 评测
  • 测评结果:WA
  • 用时:477ms
  • 内存:70056kb
  • [2023-10-17 02:36:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

bool compare_neg_score(const vector<int>& a, const vector<int>& b){
    if(a[2] > b[2]) return true;
    else if (a[2] == b[2] && a[1] > b[1]) return true;
    return false;
}

bool ncompare_neg_score(const vector<int>& a, const vector<int>& b){
    if(a[2] > b[2]) return true;
    else if (a[2] == b[2] && a[1] < b[1]) return true;
    return false;
}

int main(){
    // To get input n
    int count{0};
    cin >> count;

    // Process of solving this problem:
    // 1. First, in order to make a properly nested structure, the counts of '(' and ')' has to be the same.
    // Let the total '(' - ')' be total_score, and each string also has its score.

    // 2. In the final sequence, we will always have all strings with positive scores in the front,
    // and those with negative scores in the back, so there wont be strings like "))((" happens.

    // 3. But in positive strings, there could be a substring of negative scores. E.g. ")))((((((". 
    // Despite it has positive score, it cannot be paired with some positive strings like "(" in the front.
    // Thus, we need to calculate another score "neg_score" to indicate the substring (from the start of the string) with smallest negative score.

    // 4. If all positive strings has neg_score < 0, then it's "impossible", since it must starts with ')'.

    // 5. Sort all positive strings by their neg_score (decreasing).
    // This can guaruntee we find the possible answer without choose something like "))((" as the first string and return "impossible".
    // Check each time if the total_score - new neg_score is >= 0. If not, return "impossible".
    
    // 6. After checking all the positive strings, check the negative strings for the sequence. 
    // Reverse all negative string and check like positive strings. It's like checking the string from behind.
    // Reverse means flip all ( & ) and reverse the order.
    // When they meet in the middle, we can check if total_score = 0.
    
    // 7. If it's a valid nested structure (total_score = 0), print out the sequence. Else print "impossible".
    
    // *strings with score = 0 are stored to positive strings.

    vector<vector<int>> pos_strings(0); // save strings with positive score 
    vector<vector<int>> neg_strings(0); // save strings with negative score
    bool wrong = false; // save whether it's impossible 

    // Getting input strings
    for(int i = 0; i < count; i++){
        string s;
        int score{0}, neg_score{0}, temp_neg{0}, pos_score{0}, temp_pos{0};
        cin >> s;

        // calculate score & neg_score. Fkip the negative strings
        score = 2 * std::count(s.begin(), s.end(), '(') - s.length();

        if(score < 0){
            for(char c: s){
                if(c == '(') c = ')';
                else c = '(';
            }
            reverse(s.begin(), s.end());
        }

        for(char c: s){
            if(c == '('){
                temp_neg++;
                score++;
            }else{
                temp_neg--;
                score--;
            }
            neg_score = temp_neg < neg_score ? temp_neg : neg_score;
        }

        // save the strings to corresponding vectors
        vector<int> v = {i + 1, score, neg_score};
        if(score >= 0) pos_strings.emplace_back(v);
        else neg_strings.emplace_back(v);
    }

    // sort positive strings by neg_score (function defined above)
    sort(pos_strings.begin(), pos_strings.end(), compare_neg_score);
    sort(neg_strings.begin(), neg_strings.end(), ncompare_neg_score);
 
    // check each round that if the score went below 0. If so, print "impossible" and return
    int total_pos_score{0}; // save the current score 
    for(auto s: pos_strings){
        total_pos_score += s[1];
        if(total_pos_score + s[2] < 0){
            cout << "impossible";
            return 0;
        }
    }

    // check negatve strings
    int total_neg_score{0}; // save the current score 
    for(auto s: neg_strings){
        total_neg_score -= s[1];
        if(total_neg_score + s[2] < 0){
            cout << "impossible";
            return 0;
        }
    }

    if(total_pos_score != total_neg_score) cout << "impossible";
    else{
        // print results after passing all the checks, print neg strings in reverse order
        for(auto s: pos_strings) cout << s[0] << " ";
        for(auto it = neg_strings.rbegin(); it != neg_strings.rend(); it++) cout << (*it)[0] << " ";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 5972kb

input:

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

output:

41248 4238 13809 5338 27609 2458 389 48374 48749 6754 18533 42979 14096 6986 5803 32583 23456 31692 3405 169 26677 9225 26695 10427 38930 43508 34539 35132 30771 21764 25061 2253 24373 39743 46194 11398 46429 41740 31402 34110 35039 33777 45491 5699 23312 28794 41641 41639 6381 463 9790 35743 6701 3...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 3ms
memory: 3668kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

36 13 66 386 966 585 286 257 127 83 39 476 595 329 598 214 814 907 427 62 981 707 384 662 131 807 793 511 80 271 869 449 767 638 379 746 474 239 327 422 632 20 387 715 535 31 975 88 989 473 296 168 171 334 553 345 502 919 915 464 164 563 134 738 566 731 725 575 481 604 686 208 258 177 667 640 827 60...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2
()
()

output:

1 2 

result:

ok good plan

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2
((
))

output:

1 2 

result:

ok good plan

Test #5:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

3
()
(
)

output:

2 1 3 

result:

ok good plan

Test #7:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

3
)(
(
)

output:

2 1 3 

result:

ok good plan

Test #8:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

5
))(
(()
)(
(
)

output:

2 4 3 5 1 

result:

ok good plan

Test #9:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3
((
))())
(

output:

1 3 2 

result:

ok good plan

Test #10:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

6
)
()
()()()
((
)
)

output:

impossible

result:

ok impossible

Test #11:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

500
(
)
)
(
)(
(
(
)
))(
(
(
(
(
)
)
(
(
)
(
(
)
(
()(()
(
)())
(
(
)
(
)()((
(
)
(
)
)
(
(
(
)
(
(
)
)
)(
(
(
)
)
(
)
(
(
(
)
(
(
())))
(
(
(
)
(
)
)
(
(
)
)
(
(
(
(
(
()
(
(
(
(
(
((
)
(
(
)
(
(
(
)
())
(
(
(
)
(
(
(
)
)
(
)
)
(
)
(
(
(
(
)
(
)
)
)
)
(
)
)))()(
(
)
)
(
)
)(
)
(
)
)
))
(
(
(
(
(
(
...

output:

311 329 479 232 443 483 199 80 414 297 177 265 253 357 350 211 325 290 362 296 308 309 351 315 318 320 321 340 327 349 345 330 353 334 338 344 343 339 262 234 239 1 241 242 243 247 248 249 251 254 256 258 288 264 268 269 271 274 275 277 282 283 284 285 286 287 459 428 429 431 434 435 436 437 439 440...

result:

ok good plan

Test #12:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

50
)
)
((((()())())))(())(())
()(((()))
(((()))(()
()(((
))
)
)()))(()(()())(((((()
(
)
)
)((
)()((
())()))
(())))()
(((
))))(()
()(())(()))())()
)
)
(
(
(
(
((())()())())))(((())
()(
(()(())()((()
()(((()())))())()(
)
)((()
(
)
((
)
()(
(
(
)
)))((())
)
()))()(((()(()
((
((()))(())(()())(()())())()...

output:

6 17 28 43 5 34 4 38 37 36 32 27 25 24 23 22 10 3 46 31 14 13 29 42 9 45 44 50 49 26 16 19 15 18 48 7 40 2 8 11 12 21 1 30 33 35 39 41 47 20 

result:

ok good plan

Test #13:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

50
)
(
)()(
())(
()()(((((())(
)(())(()((())(()(()))(())())))))(())()))()())))))()(()()))(())))(()(((())(())()((())())()())(())())))()((()(()(())((()()))))()((((())()())((()))))((()()(())))))(()(())(()(()((())(()(())((()())))())(()))()())))()()((((()()((()()))((())())))()(())((()()((()((())())(()(()...

output:

26 5 11 47 46 8 40 13 28 16 18 2 41 15 33 37 19 42 44 10 4 3 29 21 6 31 36 12 17 39 43 32 7 9 14 20 22 23 24 25 27 1 34 35 38 45 48 49 50 30 

result:

ok good plan

Test #14:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

150
))(()))(())(())))()))())()()()(())(((())))()))))()
)))()(()()(()((())())))(()(()(())((())))(((()(((())()()())))()())(((((((()))((())((())(())())(()))()(()()()()((((()))(()())))()(()((()(()(((((()((()())()))((((()))()))(()(((()()(((()(((()(((())(())())(()((()))))))()())((()(())())))((()()(()(((()...

output:

17 105 142 98 12 24 120 7 28 148 87 84 69 60 38 14 11 106 92 6 111 52 73 49 79 94 140 141 149 40 37 35 32 143 100 4 15 104 130 20 136 53 48 103 93 61 89 135 91 62 23 51 70 27 133 10 16 129 117 137 96 5 102 29 77 147 125 25 2 3 9 122 56 18 47 43 86 115 41 150 134 59 30 45 85 19 55 72 50 81 31 71 63 1...

result:

ok good plan

Test #15:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

150
)))(
(()
(())((())))(()))()(()
((((()(((()))()(((((())()(()()((((()))((((()(())()(()))(()(())())(())(())))(((()))(())()))()((())((()(()(())())))))()(((()(()()())()))))()))(()(()()()(()(())()))))()))(((((())(()())((()()((((()))))(())())(())(())((()()(())))((((())((((()))()))()))))))))()())))))
(
...

output:

49 129 149 142 100 150 70 121 32 64 86 51 98 104 19 148 127 2 5 61 58 56 8 87 52 10 89 46 94 44 14 141 37 36 118 128 26 66 4 15 42 23 29 16 112 145 75 55 107 117 102 84 113 80 50 18 39 74 63 34 82 53 76 114 136 88 90 85 144 21 140 13 41 7 62 45 122 81 96 79 139 125 12 111 40 123 22 108 33 115 116 78...

result:

ok good plan

Test #16:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

150
)()((
)
)))())))
)()())((()(()())((())()))(()))(())((((((((()()(())())(()(((()))())()((()((())())))))))()((()))))((()(((()(((((()))()))((()((()()))(())))))()))))()())()()())(())(())(()))())((((((()()()))()((((()))))))((())()))()(()((()(())(())(())()())(())
()()
)
(())()))(())(()((())()()())())((...

output:

129 50 131 84 115 27 117 45 122 92 52 130 75 140 48 55 93 106 58 60 81 65 67 74 97 99 108 36 110 111 30 118 123 136 8 149 98 5 89 68 63 127 100 88 42 46 70 24 1 11 31 56 124 57 19 26 9 114 15 101 35 120 146 82 119 91 128 14 133 107 37 32 43 12 90 78 44 112 61 7 64 109 125 85 134 72 77 71 132 116 20 ...

result:

ok good plan

Test #17:

score: 0
Accepted
time: 2ms
memory: 3836kb

input:

750
(()()((()((((())()((()))()()))()))(()()(()))(()(())()))((((((
)))))))
)
((()()()(())((()(()())(())(((()((((()))(()(())((())(()())(())())))())))()(())()))((()(()((((()(()))(()())()((()()()))))(())())(())())())()((()(
)
)
(
)()(((()(())))()))))(((((((()))()()()(()())))(()())(()((
(
)
)(()))
((())(...

output:

468 163 390 379 204 396 707 590 585 4 122 1 405 657 658 601 79 180 34 274 104 473 158 149 681 571 547 504 526 730 269 705 485 108 25 230 341 103 426 395 156 406 218 246 382 494 41 43 481 408 418 131 55 56 606 166 164 530 357 378 358 581 361 362 578 574 368 369 371 374 624 326 636 622 287 618 294 612...

result:

ok good plan

Test #18:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

100
)
)
)
(
)
(
))))()
)
(
(
(
(
)
)
)
)
(
(
(
(
())
(
)
)
)((
)
(
(
(
)
(
(
)
)
)
)
()((
(
)
)
)
)(((
((((
(
)
(
)
((
)
(
(
)
(
())(()))
)
)
(
)
(
(
(
(
)))()()
)
(
(
(
(
)
(
)
)
)
(
)
)
)
)
(
)
(
(
)
(
)
(
(
(
)
)
(
)
)
(
)((((
)
)
()((()()(()))))
)
(

output:

43 48 37 68 53 57 59 60 61 62 65 66 67 50 70 74 79 81 82 84 86 87 88 91 94 100 4 6 9 10 11 12 17 18 19 20 22 27 28 29 31 32 38 44 46 51 95 42 25 98 7 54 63 21 47 45 41 40 39 36 35 34 33 30 49 24 23 16 15 14 13 8 5 3 2 26 99 97 96 93 92 90 89 85 83 80 78 52 76 75 73 72 71 69 64 58 56 55 1 77 

result:

ok good plan

Test #19:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

100
)
()(
(
)
(
)
(
(
)
)
)(()
)
)))
)
)
(
(
(
)
(
(
)
(
)
(
(
(
))(
(
(
))((
(
)
(
))())
)
(()
)
)
(
)
(
(
)
)
(
)
(
))
(
(
)
)
(
)
)
)
)
(
())
)
(
(
)
)
(
)
(
))
(
)
)
(
(
(((
(
(
(()
)
)()())(()((()((())
(
)
)
(
(
)
)
(
)
(
)
(
))(
)
(
(
(
)
(
(((())

output:

impossible

result:

ok impossible

Test #20:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

100
)
)
()))((((
))()
(
(
(
)
(
)
(
(
)
()
(
(
)
)
(
)
(
(
)
)
)
(
)
)
(
(
)
)
(
)
)
)
)
(
(
)
((
(
(
)
)
(
(
)
(
)
(()((
)
(
)
)
(()))()()())))()()((
(
)
)
(
(
(
)
)
(
(
)
(
(
(
)
(
(
)
)(
(
)
)
)
(
(())())(()
)
)
(
()
((
(
)
)
)
)
(
)
(
(
)
)
(
())
)(

output:

51 41 86 70 53 57 60 61 62 65 66 68 69 5 72 73 76 80 84 87 92 94 95 98 47 6 7 9 11 12 15 16 19 21 22 26 29 30 33 38 39 42 43 46 49 14 85 75 81 100 3 56 99 4 48 44 40 37 36 35 34 32 31 28 27 25 24 23 20 18 17 13 10 8 1 45 97 96 93 91 90 89 88 83 82 79 78 2 74 71 67 64 63 59 58 55 54 52 50 77 

result:

ok good plan

Test #21:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

100
(
(
)
(
)
(
(
(
(
)
)
)
)
()
)(
)
)
(
(
)
(
(
)
)
)
(
)
(
(
))))
(
)
(
)
(
(
(
()()(
)
())
(
(
)
)
(
(
)
(
(
)
)
(
(
(
(
(
)
(
(
(((
)
)
)
))))
(
))(
)
)
()
())()
)
)
(
)))
(
)((()))(
(
(((
((
(
)
(
(
)
(
)
)
()
)()
)
)
()))()(
)(())(
)
(
(
(
(
)(
)

output:

78 60 79 75 48 49 52 53 54 55 56 58 59 65 73 2 77 80 82 83 85 95 96 97 98 26 6 7 4 8 9 1 18 19 21 46 22 28 29 31 33 35 36 37 38 41 42 45 69 14 88 99 93 15 76 64 30 74 92 40 70 44 43 39 34 32 27 25 47 23 20 17 16 13 12 11 10 5 24 100 94 91 90 89 87 86 84 81 51 71 68 67 66 63 62 61 57 3 50 72 

result:

ok good plan

Test #22:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

1000
(())())()(((())()())(((()(()))((()((((()())))())))))(()(()((())(((()))()(()
)
(
)
()
)
)((()))))
)
((((((()))()())))))((()(
((
()(()())))(()
)()
(
((
(
)
)
)(()
)))(
)
))
(
(()))))
)(())(((())((((
)
)
(
(
())))(())
(((
(
(((
())()(
()())
)
)
)
(
))))())(
)
))(
)
())(()(()))))()(()((())((((()())...

output:

impossible

result:

ok impossible

Test #23:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

1000
))(()))
(
)))(
)
((
()))()))))()()(
))))((((((((()()(())((()()
(
)
)()(()
(
()))))()
(
(()(()(((()())(((((((())()()())())(())()))))((()((())((((((()(()()
)(()())((()))
(((
)
)
(
)((
(
(
)
(
)
()(())(((
(
)
(
(
)
()(()(()()(()()((()))())((()())))))((())(((()()(())(()()())(()()(((())()(()((((((((...

output:

impossible

result:

ok impossible

Test #24:

score: 0
Accepted
time: 2ms
memory: 4080kb

input:

4000
(
)
))
)()))))(
(
)
(
)
)
)
)((()((
(
)
)()(
)
)
)
)
(
)
(
)
)
(
()))((()))))()((()(
(
)))
(
)
(
(
(
(
)
)()(()()(()()))))())
)
)
)(((
)
)
)
)
(
(
)
))()()))((())
(
(
)
(
))(
(
)
)
(
)
)
())(
)
(
(
(
)
())))(())((()(()()((()((
(
)
)
(
)
)
)
)
)
)
)
)
(
)
(()))))(
)
)
(
())))(((())()(
(
(
()(
(
...

output:

impossible

result:

ok impossible

Test #25:

score: 0
Accepted
time: 362ms
memory: 70056kb

input:

1000000
)
(
)()(((()))(
(
(
(
)
(
(
)
)
(((())((()(()((())
(
)
)(
)
)
))))(()))()())(()((()))(()()()))()()()))))))))(())))((((()(()()))((((((()((((()()(
)
((
)
)
(
)
())()()((
)
)))(())((()))((()()))(()(())())))())))())))(()()(
(
()(
(
(
()()
)
))
)
(
(
(
)
)
)
(
)
(
)
)
)
)(()))()))
(
)
)))
(
)
(
(...

output:

149392 264227 387984 770337 898404 83071 995820 269214 349084 857929 897909 731069 604894 385160 174818 196234 765299 352796 904916 760108 134097 708004 526593 308325 489285 592970 675083 748267 911588 501576 540367 992894 309146 900795 160328 342091 474263 197429 267140 619800 475916 610823 507757 ...

result:

ok good plan

Test #26:

score: 0
Accepted
time: 109ms
memory: 19304kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #27:

score: 0
Accepted
time: 108ms
memory: 20096kb

input:

1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))...

output:

impossible

result:

ok impossible

Test #28:

score: 0
Accepted
time: 95ms
memory: 20740kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 

result:

ok good plan

Test #29:

score: 0
Accepted
time: 95ms
memory: 19600kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #30:

score: 0
Accepted
time: 109ms
memory: 19748kb

input:

1
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

impossible

result:

ok impossible

Test #31:

score: 0
Accepted
time: 106ms
memory: 17744kb

input:

2
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))...

output:

2 1 

result:

ok good plan

Test #32:

score: 0
Accepted
time: 113ms
memory: 15688kb

input:

2
)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(...

output:

impossible

result:

ok impossible

Test #33:

score: 0
Accepted
time: 113ms
memory: 19688kb

input:

3
)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(...

output:

3 1 2 

result:

ok good plan

Test #34:

score: 0
Accepted
time: 279ms
memory: 58260kb

input:

1000000
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((((((
((((((...

output:

impossible

result:

ok impossible

Test #35:

score: 0
Accepted
time: 285ms
memory: 58900kb

input:

1000000
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))))))
))))))...

output:

impossible

result:

ok impossible

Test #36:

score: 0
Accepted
time: 355ms
memory: 57812kb

input:

1000000
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))))))
((((((((((
))))))...

output:

666658 666688 666686 666684 666682 666680 666678 666676 666674 666672 666670 666668 666666 666664 666662 666660 666690 666656 666654 666652 666650 666648 666646 666644 666642 666640 666638 666636 666634 666632 666630 666720 666750 666748 666746 666744 666742 666740 666738 666736 666734 666732 666730...

result:

ok good plan

Test #37:

score: 0
Accepted
time: 323ms
memory: 57968kb

input:

999999
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)...

output:

833328 833343 833342 833341 833340 833339 833338 833337 833336 833335 833334 833333 833332 833331 833330 833329 833344 833327 833326 833325 833324 833323 833322 833321 833320 833319 833318 833317 833316 833315 833314 833359 833374 833373 833372 833371 833370 833369 833368 833367 833366 833365 833364...

result:

ok good plan

Test #38:

score: 0
Accepted
time: 461ms
memory: 68448kb

input:

1000000
)(
()(()))()((
)())
)()((((((
((((
))))))))()())((()(
)((
)())
))()((()
()
(
)(
()(
(((()((()())(()))(((())(((
)()()
)))(
(((
(()(()(())))(())))(((((
())())((()))(
(())
(()
()))(()(())()())(
())((
)))))))))
())()((())))(
()())((((()())()
((
()())
()((())
)()))))))))()())()))())
()())
)()())
...

output:

510441 164663 944202 483356 500584 889056 637097 732016 879218 183559 679768 163748 496501 90286 763948 924596 911154 629235 321244 428626 590693 323909 598737 475331 261112 651410 378339 480176 295142 67591 970762 850025 235797 947844 451519 354542 553153 130656 491924 740159 897141 766848 880821 4...

result:

ok good plan

Test #39:

score: 0
Accepted
time: 477ms
memory: 67360kb

input:

1000000
)()))))(()(((()
()((((()))
)())
)
()()(
()
())()((())))))())()(())(())
())))()())((
)()()((()((())
)
)()(
()()(
((())((
)(
(
)((()((()((()(())(()())
))()
())
()()()
(())
))()(()(()()()()((
(())))()((((()()(
(())
)())((()))
))(()
()()()(()(()()((((())))((())))(()()(()))))
(()()))()(())))()))(...

output:

568499 250826 629151 494698 675014 536620 795023 425960 985988 926090 463859 561779 300744 106383 575206 137311 597972 689231 963161 353729 427235 388609 333208 207485 746420 129338 930603 770416 123122 623824 905927 834142 116108 470327 997127 696104 487205 437875 713994 12900 192291 289835 209291 ...

result:

ok good plan

Test #40:

score: -100
Wrong Answer
time: 140ms
memory: 3876kb

input:

564
)())((())((()))))(()())((((()()(()(()))(()((((()()))(((()))(()()()(()((()()()()((()))))((())))()(()((())(()())))))))())))(((())()()()))))()((((()()))()(()()())))(()()(())((())((()())(()()())()(((()))()())())))(((()(((((()())()())))()()((())))()()()(()()))()(()()()(((())())))(()(()(()((())()((()(...

output:

impossible

result:

wrong answer you didn't find a solution but jury did