QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214795#5108. Prehistoric ProgramsYYYYYYYYRE 0ms0kbC++142.4kb2023-10-15 00:04:462023-10-15 00:04:46

Judging History

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

  • [2023-10-15 00:04:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-15 00:04:46]
  • 提交

answer

#include <bits/stdc++.h>

void processString(int info[4], int num){
    int left = 0, right = 0;
    std::string str;
    std::cin >> str;
    int mn = 0, cur = 0;
	for(auto x : str){
		if(x == '(') cur++;
		else cur--;
		mn = std::min(mn, cur);
	}
	cur -= mn;
    info[0] = num + 1;
    info[1] = cur;
    info[2] = -mn;
    return;
}

void swap(int arr1[4], int arr2[4]){
    int temp0 = arr1[0], temp1 = arr1[1], temp2 = arr1[2], temp3 = arr1[3];
    arr1[0] = arr2[0];
    arr1[1] = arr2[1];
    arr1[2] = arr2[2];
    arr1[3] = arr2[3];
    arr2[0] = temp0;
    arr2[1] = temp1;
    arr2[2] = temp2;
    arr2[3] = temp3;
    return;
}

int selfDefinedCompare(int a[4], int b[4]){
    int s1 = (a[1] == a[2] ? 0 : (a[1] > a[2] ? 1 : -1));
	int s2 = (b[1] == b[2] ? 0 : (b[1] > b[2] ? 1 : -1));
	if(s1 != s2) return (s1 > s2 ? 3 : 1);
	if(s1 == 1) return (a[2] < b[2] ? 3 : 1);
	else return (a[1] >= b[1] ? 3 : 1);
}

 
int partition(int info[][4], int start, int end){
    int* pivot = info[start];
    int count = 0;
    for (int i = start + 1; i <= end; i++) {
        if (selfDefinedCompare(info[i], pivot) == 3)
            count++;
    }
    int pivotIndex = start + count;
    swap(info[pivotIndex], info[start]);
    int i = start, j = end;
    while (i < pivotIndex && j > pivotIndex){
        while (selfDefinedCompare(info[i], pivot) == 3){
            i++;
        }
        while (selfDefinedCompare(info[j], pivot) == 1){
            j--;
        }
        if (i < pivotIndex && j > pivotIndex){
            swap(info[i++], info[j--]);
        }
    }
    return pivotIndex;
}
 
void quickSort(int info[][4], int start, int end){
    if (start >= end)
        return;
    int p = partition(info, start, end);
    quickSort(info, start, p - 1);
    quickSort(info, p + 1, end);
}

bool check(int num, int info[][4]){
    int mn = 0, cur = 0;
    for(int i = 0; i < num; i++){
        auto x = info[i];
		mn = std::min(mn, cur - x[2]);
		cur += x[1] - x[2];
	}
	
	if(mn < 0 || cur != 0) return false;
	return true;
}

int main() {
    int num, info[100000][4];
    std::cin >> num;
    for(int i = 0; i < num; i++) processString(info[i], i);
    quickSort(info, 0, num - 1);
    if(true){
        for(int i = 0; i < num; i++){
            std::cout << info[i][0] << "\n";
        }
    } else{
        std::cout << "impossible";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: