답안 #645602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645602 2022-09-27T12:51:12 Z Pety Homework (CEOI22_homework) C++14
100 / 100
215 ms 209576 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

string s;
vector<vector<int>>v;

struct subarbore {
  int st, dr, cnt;
};

subarbore rec (int st, int dr, int l) {
  if (st + 1 == dr) {
    return {1, 1, 1};
  }
  int mid = *lower_bound(v[l - 1].begin(), v[l - 1].end(), st);
  subarbore a = rec(st + 4, mid, l + 1);
  subarbore b = rec(mid + 1, dr - 1, l + 1);
  if (s[st + 1] == 'a') {
    return {a.st + b.st, max(a.dr + b.cnt, b.dr + a.cnt), a.cnt + b.cnt};
  }
  else {
    a.st = a.cnt - a.st + 1;
    a.dr = a.cnt - a.dr + 1;
    b.st = b.cnt - b.st + 1;
    b.dr = b.cnt - b.dr + 1;
    swap(a.st, a.dr);
    swap(b.st, b.dr);

    return {a.cnt + b.cnt - max(a.dr + b.cnt, b.dr + a.cnt) + 1, a.cnt + b.cnt - (a.st + b.st) + 1, a.cnt + b.cnt};
  }
}


int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> s;
  s = '#' + s;
  int cnt = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == '(') 
      cnt++;
    if (s[i] == ')')
      cnt--;
    if (s[i] == ',') {
      while (v.size() < cnt)
        v.push_back({});
      v[cnt - 1].push_back(i);
    }  
  }
  subarbore ans = rec(1, s.size(), 1);
  cout << ans.dr - ans.st + 1;
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for (int i = 1; i < s.size(); i++) {
      |                   ~~^~~~~~~~~~
Main.cpp:52:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |       while (v.size() < cnt)
      |              ~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 320 KB Output is correct
49 Correct 0 ms 316 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 300 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 207696 KB Output is correct
2 Correct 201 ms 208308 KB Output is correct
3 Correct 204 ms 207848 KB Output is correct
4 Correct 196 ms 209396 KB Output is correct
5 Correct 193 ms 209216 KB Output is correct
6 Correct 204 ms 209384 KB Output is correct
7 Correct 200 ms 208704 KB Output is correct
8 Correct 195 ms 208936 KB Output is correct
9 Correct 189 ms 208100 KB Output is correct
10 Correct 188 ms 207864 KB Output is correct
11 Correct 189 ms 209576 KB Output is correct
12 Correct 194 ms 208088 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 320 KB Output is correct
49 Correct 0 ms 316 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 300 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 324 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 324 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 324 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 0 ms 316 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 1 ms 212 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 316 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 320 KB Output is correct
49 Correct 0 ms 316 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 300 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 215 ms 207696 KB Output is correct
58 Correct 201 ms 208308 KB Output is correct
59 Correct 204 ms 207848 KB Output is correct
60 Correct 196 ms 209396 KB Output is correct
61 Correct 193 ms 209216 KB Output is correct
62 Correct 204 ms 209384 KB Output is correct
63 Correct 200 ms 208704 KB Output is correct
64 Correct 195 ms 208936 KB Output is correct
65 Correct 189 ms 208100 KB Output is correct
66 Correct 188 ms 207864 KB Output is correct
67 Correct 189 ms 209576 KB Output is correct
68 Correct 194 ms 208088 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 324 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 324 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 324 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 0 ms 316 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 1 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 116 ms 20680 KB Output is correct
101 Correct 120 ms 19860 KB Output is correct
102 Correct 123 ms 19728 KB Output is correct
103 Correct 112 ms 19944 KB Output is correct
104 Correct 115 ms 19112 KB Output is correct
105 Correct 147 ms 80212 KB Output is correct
106 Correct 147 ms 79792 KB Output is correct
107 Correct 133 ms 80200 KB Output is correct
108 Correct 143 ms 80848 KB Output is correct
109 Correct 154 ms 81332 KB Output is correct
110 Correct 140 ms 20884 KB Output is correct
111 Correct 134 ms 19820 KB Output is correct
112 Correct 137 ms 20312 KB Output is correct
113 Correct 137 ms 19596 KB Output is correct
114 Correct 145 ms 20208 KB Output is correct
115 Correct 193 ms 209380 KB Output is correct
116 Correct 191 ms 208500 KB Output is correct
117 Correct 190 ms 209256 KB Output is correct
118 Correct 191 ms 208448 KB Output is correct
119 Correct 184 ms 208236 KB Output is correct
120 Correct 143 ms 20388 KB Output is correct
121 Correct 132 ms 20536 KB Output is correct
122 Correct 135 ms 20292 KB Output is correct
123 Correct 147 ms 20440 KB Output is correct
124 Correct 152 ms 114828 KB Output is correct
125 Correct 155 ms 114552 KB Output is correct
126 Correct 143 ms 113972 KB Output is correct
127 Correct 144 ms 115012 KB Output is correct
128 Correct 57 ms 10956 KB Output is correct
129 Correct 51 ms 10668 KB Output is correct
130 Correct 46 ms 10960 KB Output is correct
131 Correct 0 ms 212 KB Output is correct