QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217812#5108. Prehistoric ProgramsdrldrlsWA 495ms70828kbC++174.5kb2023-10-17 14:35:222023-10-17 14:35:22

Judging History

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

  • [2023-10-17 14:35:22]
  • 评测
  • 测评结果:WA
  • 用时:495ms
  • 内存:70828kb
  • [2023-10-17 14:35:22]
  • 提交

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;
}

详细

Test #1:

score: 100
Accepted
time: 21ms
memory: 6000kb

input:

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

output:

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

result:

ok good plan

Test #2:

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

input:

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

output:

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

result:

ok good plan

Test #3:

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

input:

2
()
()

output:

2 1 

result:

ok good plan

Test #4:

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

input:

2
((
))

output:

1 2 

result:

ok good plan

Test #5:

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

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

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

input:

3
()
(
)

output:

2 3 1 

result:

ok good plan

Test #7:

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

input:

3
)(
(
)

output:

2 1 3 

result:

ok good plan

Test #8:

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

input:

5
))(
(()
)(
(
)

output:

2 4 3 5 1 

result:

ok good plan

Test #9:

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

input:

3
((
))())
(

output:

1 3 2 

result:

ok good plan

Test #10:

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

input:

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

output:

impossible

result:

ok impossible

Test #11:

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

input:

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

output:

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

result:

ok good plan

Test #12:

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

input:

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

output:

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

result:

ok good plan

Test #13:

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

input:

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

output:

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

result:

ok good plan

Test #14:

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

input:

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

output:

17 105 142 24 98 12 120 7 148 28 11 14 106 38 60 87 84 69 140 49 52 73 79 111 92 94 100 104 141 4 6 149 15 143 32 35 40 37 93 61 89 135 91 62 23 27 51 70 10 16 133 102 29 147 77 125 25 2 3 9 122 56 18 47 43 86 150 134 59 30 45 19 72 50 81 31 71 63 127 116 66 21 57 54 121 126 55 110 132 42 8 90 109 1...

result:

ok good plan

Test #15:

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

input:

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

output:

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

result:

ok good plan

Test #16:

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

input:

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

output:

129 50 131 84 115 27 117 45 122 52 92 75 130 140 110 74 93 67 65 97 99 106 108 81 111 118 123 136 149 8 60 30 36 58 48 55 63 127 100 42 46 88 70 24 56 31 1 11 114 15 101 35 120 146 82 119 133 107 37 32 43 12 90 78 44 112 61 7 64 109 125 85 134 72 71 77 132 116 20 95 34 23 4 22 148 16 66 150 51 39 83...

result:

ok good plan

Test #17:

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

input:

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

output:

468 163 379 390 204 396 707 585 590 4 122 1 657 658 601 405 180 34 104 79 274 158 473 705 25 526 108 149 571 485 681 730 269 504 547 166 246 481 131 426 164 606 418 156 103 408 382 218 55 56 230 43 341 395 494 41 530 406 502 470 469 743 518 512 500 475 477 495 492 490 491 437 409 374 378 749 383 384...

result:

ok good plan

Test #18:

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

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: 3620kb

input:

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

output:

impossible

result:

ok impossible

Test #20:

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

input:

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

output:

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

result:

ok good plan

Test #21:

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

input:

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

output:

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

result:

ok good plan

Test #22:

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

input:

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

output:

impossible

result:

ok impossible

Test #23:

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

input:

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

output:

impossible

result:

ok impossible

Test #24:

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

input:

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

output:

impossible

result:

ok impossible

Test #25:

score: 0
Accepted
time: 366ms
memory: 70828kb

input:

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

output:

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

result:

ok good plan

Test #26:

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

input:

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

output:

impossible

result:

ok impossible

Test #27:

score: 0
Accepted
time: 103ms
memory: 18752kb

input:

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

output:

impossible

result:

ok impossible

Test #28:

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

input:

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

output:

1 

result:

ok good plan

Test #29:

score: 0
Accepted
time: 107ms
memory: 19516kb

input:

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

output:

impossible

result:

ok impossible

Test #30:

score: 0
Accepted
time: 111ms
memory: 19316kb

input:

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

output:

impossible

result:

ok impossible

Test #31:

score: 0
Accepted
time: 105ms
memory: 17380kb

input:

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

output:

2 1 

result:

ok good plan

Test #32:

score: 0
Accepted
time: 107ms
memory: 17664kb

input:

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

output:

impossible

result:

ok impossible

Test #33:

score: 0
Accepted
time: 104ms
memory: 19904kb

input:

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

output:

3 1 2 

result:

ok good plan

Test #34:

score: 0
Accepted
time: 280ms
memory: 58552kb

input:

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

output:

impossible

result:

ok impossible

Test #35:

score: 0
Accepted
time: 263ms
memory: 58200kb

input:

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

output:

impossible

result:

ok impossible

Test #36:

score: 0
Accepted
time: 356ms
memory: 57940kb

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: 310ms
memory: 58040kb

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: 480ms
memory: 68076kb

input:

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

output:

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

result:

ok good plan

Test #39:

score: 0
Accepted
time: 495ms
memory: 67048kb

input:

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

output:

250826 568499 494698 629151 675014 985988 425960 795023 536620 463859 561779 926090 300744 106383 575206 689231 137311 597972 333208 930603 129338 388609 963161 746420 427235 353729 207485 834142 487205 770416 123122 997127 696104 470327 905927 116108 623824 357972 391833 460894 836351 902316 186938...

result:

ok good plan

Test #40:

score: -100
Wrong Answer
time: 136ms
memory: 4136kb

input:

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

output:

impossible

result:

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