QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215611#5108. Prehistoric ProgramsYYYYYYYYWA 18ms6072kbC++142.1kb2023-10-15 12:09:012023-10-15 12:09:01

Judging History

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

  • [2023-10-15 12:09:01]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:6072kb
  • [2023-10-15 12:09:01]
  • 提交

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

    std::vector<int> v;
    std::vector<int> value0;
    std::vector<int> value1;
	std::vector<int> right;
	std::vector<int> left;
    int middle = 0;
    int cur[2]={0};
    int flag = 0;
	right.insert(right.begin(),0);
	left.insert(left.begin(),0);
    // for(int i = 0; i < n; i++){
        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 < v.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: 18ms
memory: 6072kb

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: 2ms
memory: 3684kb

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

input:

2
()
()

output:

1 2 

result:

ok good plan

Test #4:

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

input:

2
((
))

output:

1 2 

result:

ok good plan

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

2
)(
()

output:

1 2 

result:

wrong answer wrong plan (expected impossible)