QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215572#5108. Prehistoric ProgramsYYYYYYYYCompile Error//C++142.3kb2023-10-15 11:53:392023-10-15 11:53:40

Judging History

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

  • [2023-10-15 11:53:40]
  • 评测
  • [2023-10-15 11:53:39]
  • 提交

answer

#include <iostream>
#include <cstring>
#include<string> 
#include <vector>
#include <functional>

int main() {
    int n = 0;
    std::string parentheses;
    // int in[100000][2]={0};//[),(]
    std::cin >> n;
    int sum = 0;
	std::vector<std::vector<int>> in(n, std::vector<int>(3, 0));

    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 con1 = 0;
		int con2 = 0;
		
		
		
		
		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;
}
/*
3
(((
)))
)(
 */   
/*
2
)(
)(
*/
/*
7
)))(
)(
()
)(
((((()
))
()
*/
/*
6
)((
(
(
)((((((
)
))))))))(
*/

詳細信息

answer.code: In function ‘int main()’:
answer.code:52:14: error: ‘sort’ is not a member of ‘std’; did you mean ‘qsort’?
   52 |         std::sort(in.begin(), in.end(), [](const std::vector<int>& a, const std::vector<int>& b){
      |              ^~~~
      |              qsort