QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214774 | #5108. Prehistoric Programs | YYYYYYYY | WA | 217ms | 5152kb | C++14 | 2.4kb | 2023-10-14 23:50:03 | 2023-10-14 23:50:03 |
Judging History
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(check(num, info)){
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
Wrong Answer
time: 217ms
memory: 5152kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did