QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215624#5108. Prehistoric ProgramsYYYYYYYYWA 19ms5968kbC++141.8kb2023-10-15 12:16:092023-10-15 12:16:10

Judging History

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

  • [2023-10-15 12:16:10]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:5968kb
  • [2023-10-15 12:16:09]
  • 提交

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";
    // 	return 0;
	// }

    
  
    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 < in.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: 100
Accepted
time: 19ms
memory: 5968kb

input:

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

output:

26315 26345 26341 26339 26336 26334 26333 26329 26328 26327 26321 26320 26318 26317 26316 26347 26313 26311 26308 26307 26305 26302 26297 26295 26294 26292 26290 26289 26286 26384 26414 26413 26412 26409 26406 26402 26401 26399 26398 26396 26395 26394 26393 26285 26383 26382 26380 26376 26370 26366 ...

result:

ok good plan

Test #2:

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

input:

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

output:

598 268 267 265 590 258 257 929 595 253 252 271 933 934 247 245 243 242 604 935 239 827 287 563 564 919 301 566 296 570 291 290 573 826 286 575 576 282 577 280 925 584 585 814 945 198 636 638 947 640 190 189 188 948 632 646 182 181 179 178 177 650 652 171 216 825 611 229 228 615 619 223 820 819 217 ...

result:

ok good plan

Test #3:

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

input:

2
()
()

output:

1 2 

result:

ok good plan

Test #4:

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

input:

2
((
))

output:

1 2 

result:

ok good plan

Test #5:

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

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

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

input:

3
()
(
)

output:

2 1 3 

result:

ok good plan

Test #7:

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

input:

3
)(
(
)

output:

2 1 3 

result:

ok good plan

Test #8:

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

input:

5
))(
(()
)(
(
)

output:

2 4 3 1 5 

result:

ok good plan

Test #9:

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

input:

3
((
))())
(

output:

1 3 2 

result:

ok good plan

Test #10:

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

input:

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

output:

impossible

result:

ok impossible

Test #11:

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

input:

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

output:

203 414 211 210 209 208 207 415 205 413 416 199 198 196 420 194 192 191 405 398 234 399 232 228 227 226 404 424 406 219 409 410 411 412 214 442 437 439 440 160 159 158 157 156 436 153 152 443 149 445 143 449 141 178 186 426 184 427 182 428 180 429 395 177 176 431 171 434 435 166 362 318 315 356 357 ...

result:

ok good plan

Test #12:

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

input:

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

output:

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

result:

ok good plan

Test #13:

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

input:

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

output:

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

result:

ok good plan

Test #14:

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

input:

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

output:

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

result:

ok good plan

Test #15:

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

input:

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

output:

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

result:

ok good plan

Test #16:

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

input:

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

output:

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

result:

ok good plan

Test #17:

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

input:

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

output:

230 665 243 450 585 668 238 669 455 231 246 229 228 227 672 225 224 584 673 220 258 657 658 265 264 263 440 441 442 259 674 588 661 255 587 446 250 663 664 690 184 182 181 180 473 176 175 475 172 185 169 477 166 164 163 162 160 159 158 680 218 581 214 213 212 461 677 208 204 269 681 195 578 684 468 ...

result:

ok good plan

Test #18:

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

input:

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

output:

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

result:

ok good plan

Test #19:

score: -100
Wrong Answer
time: 1ms
memory: 3532kb

input:

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

output:

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

result:

wrong answer wrong plan (expected impossible)