11530 | 2024-10-19 10:50:09 | Dávid | Bob Baba Zárójelsorozata | cpp17 | Wrong answer 20/100 | 598ms | 568 KiB |
#include <bits/stdc++.h>
#include <utility>
#include <vector>
using namespace std;
int n;
vector<long long> prefix;
vector<pair<int, int>> szamolas(int b) {
vector<pair<int, int>> eredmeny;
pair<int, int> par = pair<int, int>(-1, -1);
if(b >= n) par = pair<int, int>(0, 0);
int j = b + 1;
for(int i = b + 2; i <= n; i++) {
while(prefix[j] - prefix[b] < prefix[i] - prefix[j]) {
j++;
}
if(prefix[j] - prefix[b] == prefix[i] - prefix[j]) {
par = pair<int, int>(j, i);
eredmeny = szamolas(i);
}
}
eredmeny.push_back(par);
return eredmeny;
}
int main() {
cin >> n;
prefix.resize(n + 1);
for(int i = 1; i <= n; i++) {
cin >> prefix[i];
prefix[i] += prefix[i - 1];
}
vector<pair<int, int>> eredmeny = szamolas(0);
if(eredmeny[0].first == -1) {
cout << -1 << endl;
return 0;
}
reverse(eredmeny.begin(), eredmeny.end());
int j = 0;
for(long long i = 1; i <= prefix[n]; i++) {
if(i <= prefix[eredmeny[j].first]) {
cout << "(";
} else if(i <= prefix[eredmeny[j].second]) {
cout << ")";
} else {
j++;
cout << "(";
}
}
cout << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 508 KiB | ||||
2 | Accepted | 1ms | 320 KiB | ||||
3 | Accepted | 1ms | 508 KiB | ||||
subtask2 | 20/20 | ||||||
4 | Accepted | 1ms | 320 KiB | ||||
5 | Accepted | 1ms | 412 KiB | ||||
6 | Accepted | 1ms | 320 KiB | ||||
subtask3 | 0/30 | ||||||
7 | Wrong answer | 1ms | 508 KiB | ||||
8 | Wrong answer | 1ms | 320 KiB | ||||
9 | Wrong answer | 1ms | 508 KiB | ||||
10 | Accepted | 1ms | 320 KiB | ||||
11 | Wrong answer | 1ms | 320 KiB | ||||
subtask4 | 0/50 | ||||||
12 | Accepted | 1ms | 320 KiB | ||||
13 | Wrong answer | 1ms | 508 KiB | ||||
14 | Wrong answer | 1ms | 320 KiB | ||||
15 | Wrong answer | 1ms | 408 KiB | ||||
16 | Accepted | 1ms | 320 KiB | ||||
17 | Accepted | 1ms | 320 KiB | ||||
18 | Accepted | 1ms | 412 KiB | ||||
19 | Wrong answer | 1ms | 320 KiB | ||||
20 | Wrong answer | 1ms | 320 KiB | ||||
21 | Wrong answer | 1ms | 392 KiB | ||||
22 | Accepted | 1ms | 320 KiB | ||||
23 | Accepted | 1ms | 320 KiB | ||||
24 | Accepted | 1ms | 508 KiB | ||||
25 | Wrong answer | 1ms | 408 KiB | ||||
26 | Wrong answer | 1ms | 320 KiB | ||||
27 | Accepted | 1ms | 404 KiB | ||||
28 | Accepted | 1ms | 336 KiB | ||||
29 | Accepted | 1ms | 568 KiB | ||||
30 | Accepted | 1ms | 320 KiB | ||||
31 | Wrong answer | 1ms | 396 KiB | ||||
32 | Wrong answer | 1ms | 320 KiB | ||||
33 | Accepted | 1ms | 320 KiB | ||||
34 | Accepted | 1ms | 560 KiB | ||||
35 | Accepted | 1ms | 320 KiB | ||||
36 | Wrong answer | 1ms | 408 KiB | ||||
37 | Wrong answer | 1ms | 320 KiB | ||||
38 | Wrong answer | 1ms | 320 KiB | ||||
39 | Wrong answer | 1ms | 508 KiB | ||||
40 | Wrong answer | 1ms | 320 KiB | ||||
41 | Wrong answer | 1ms | 568 KiB | ||||
42 | Wrong answer | 1ms | 320 KiB | ||||
43 | Wrong answer | 1ms | 320 KiB | ||||
44 | Wrong answer | 1ms | 508 KiB | ||||
45 | Wrong answer | 1ms | 568 KiB | ||||
46 | Wrong answer | 1ms | 320 KiB | ||||
47 | Wrong answer | 1ms | 512 KiB | ||||
48 | Wrong answer | 1ms | 320 KiB | ||||
49 | Wrong answer | 1ms | 320 KiB | ||||
50 | Wrong answer | 1ms | 408 KiB | ||||
51 | Wrong answer | 1ms | 320 KiB | ||||
52 | Wrong answer | 1ms | 404 KiB | ||||
53 | Time limit exceeded | 598ms | 320 KiB | ||||
54 | Time limit exceeded | 598ms | 320 KiB | ||||
55 | Wrong answer | 1ms | 320 KiB | ||||
56 | Wrong answer | 1ms | 320 KiB | ||||
57 | Wrong answer | 1ms | 320 KiB | ||||
58 | Wrong answer | 1ms | 320 KiB |