QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215491#5108. Prehistoric ProgramsYYYYYYYYWA 31ms4532kbC++143.2kb2023-10-15 11:07:252023-10-15 11:07:26

Judging History

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

  • [2023-10-15 11:07:26]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:4532kb
  • [2023-10-15 11:07:25]
  • 提交

answer

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

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

    for (int i = 0; i < n; i++) {
        std::cin >> parentheses;
		int par = 0;
        while(parentheses[par]!='\0'){
        	if(parentheses[par]=='('){
        		in[i][1] += 1;
			}
			else if(parentheses[par]==')'){
				if(in[i][1]>0){
					in[i][1] -= 1;
				}
				else {
					in[i][0] += 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++){
        middle = v.size()/2;
		
		if(in[i][1]==0 && in[i][0]!=0){//only)
            // v.push_back(i+1);
            // value0.push_back(in[i][0]);
            // value1.push_back(in[i][1]);
            // flag -= in[i][0];

			right[0] += in[i][0];
			right.push_back(i+1);
         
        }
        else if(in[i][0]==0 && in[i][1]!=0){
        //    v.insert(v.begin(), i+1);
        //    value0.insert(value0.begin(), in[i][0]);
        //    value1.insert(value1.begin(), in[i][1]);
        //    flag += in[i][1];
			left[0] += in[i][1];
			left.push_back(i+1);
          
        }

		else if(v.size()==0){
			// std::cout<<"Y"<<middle;
			v.insert(v.begin()+middle, i+1);
            value0.insert(value0.begin()+middle, in[i][0]);
            value1.insert(value1.begin()+middle, in[i][1]);
		}
        else if(in[i][0]-in[i][1]==0){
            // std::cout<<"-->"<<flag;
            // if(flag >0){
            //     middle++;
            // }
			v.insert(v.begin()+middle, i+1);
            value0.insert(value0.begin()+middle, in[i][0]);
            value1.insert(value1.begin()+middle, in[i][1]);
           
		}
        
    	else if(in[i][0]-in[i][1]>0){//)多,放後
    		 v.push_back(i+1);
            value0.push_back(in[i][0]);
            value1.push_back(in[i][1]);
           
		}
		else if(in[i][0]-in[i][1]<0){
			v.insert(v.begin()+middle, i+1);
            value0.insert(value0.begin()+middle, in[i][0]);
            value1.insert(value1.begin()+middle, in[i][1]);
           
		}
	}

	//v[i] = left+v+right
    sum = left[0];
	// std::cout<<"left"<<left[0]<<"right"<<right[0];
    for(int i = 0; i < v.size(); i++){
        // std::cout<<value0[i]<<"?";
        sum -= value0[i];
        if(sum<0){
            std::cout<<"impossible"; 
    	    return 0;
        }
        sum+=value1[i];
    }
	if(sum-right[0]<0){
		//  std::cout<<"impossible"; 
    	//  return 0;
	}
	for (int i = 1; i < left.size(); i++) {
		std::cout << left[i] << " ";
	}
	for (int i = 0; i < v.size(); i++) {
		std::cout << v[i] << " ";
	}
	for (int i = 1; i < right.size(); i++) {
		std::cout << right[i] << " ";
	}
	
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 31ms
memory: 4532kb

input:

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

output:

0 10 19 71 00 11 00 30 10 10 10 10 10 00 11 00 11 35 10 11 02 01 00 11 01 01 10 10 10 00 11 00 11 10 10 11 10 10 11 01 01 00 10 10 116 01 01 01 01 01 01 01 05 20 30 11 04 30 10 11 00 12 01 22 00 01 01 01 00 00 11 00 11 01 01 00 70 71 00 10 11 15 21 14 01 011 70 11 01 01 00 10 10 10 10 10 10 11 00 17...

result:

wrong answer wrong output