QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214765#5108. Prehistoric ProgramsYYYYYYYYWA 307ms5400kbC++142.4kb2023-10-14 23:45:242023-10-14 23:45:25

Judging History

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

  • [2023-10-14 23:45:25]
  • 评测
  • 测评结果:WA
  • 用时:307ms
  • 内存:5400kb
  • [2023-10-14 23:45:24]
  • 提交

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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 307ms
memory: 5400kb

input:

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

output:

2
50000
49997
5
49991
7
8
9
10
11
12
49990
14
49989
16
49986
49981
19
49979
49977
49973
23
49971
49970
49968
27
28
49967
30
49964
32
49963
34
35
49962
37
38
49961
49957
49956
42
43
44
49953
49951
49949
49946
49945
49944
49942
49941
49938
54
55
49935
49932
58
59
49923
61
49919
49917
49916
49915
49914...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 2ms
memory: 5200kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

999
3
799
268
995
267
992
265
10
801
12
13
14
989
258
17
18
988
20
257
22
803
804
253
252
984
807
808
811
31
981
33
247
245
36
243
242
39
977
975
814
239
819
820
966
822
963
229
228
825
826
827
54
223
217
216
58
215
60
948
62
214
64
65
66
213
212
947
209
945
208
206
943
75
846
77
198
852
80
935
934
...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 1ms
memory: 5148kb

input:

2
()
()

output:

2
1

result:

ok good plan

Test #4:

score: 0
Accepted
time: 1ms
memory: 5084kb

input:

2
((
))

output:

1
2

result:

ok good plan

Test #5:

score: 0
Accepted
time: 1ms
memory: 5064kb

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

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

input:

3
()
(
)

output:

2
1
3

result:

ok good plan

Test #7:

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

input:

3
)(
(
)

output:

2
1
3

result:

ok good plan

Test #8:

score: 0
Accepted
time: 1ms
memory: 5080kb

input:

5
))(
(()
)(
(
)

output:

2
4
3
1
5

result:

ok good plan

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 5156kb

input:

3
((
))())
(

output:

impossible

result:

wrong answer you didn't find a solution but jury did