Submission #735868

# Submission time Handle Problem Language Result Execution time Memory
735868 2023-05-04T20:49:16 Z tch1cherin Homework (CEOI22_homework) C++17
100 / 100
470 ms 202296 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> g;
vector<int> t, S, Min, Max;

void DFS(int u) {
  if (t[u] == 3) {
    Min[u] = Max[u] = S[u] = 1;
    return;
  }
  for (int v : g[u]) {
    DFS(v);
    S[u] += S[v];
    if (t[u] == 1) {
      Max[u] += S[v] - Max[v] + 1; 
    } else {
      Min[u] += Min[v];
    }
  }
  if (t[u] == 1) {
    Min[u] = S[u];
    for (int v : g[u]) {
      Min[u] = min(Min[u], Min[v]);
    }
    Max[u] = S[u] - Max[u] + 1; 
  } else { 
    Max[u] = 1;
    for (int v : g[u]) {
      Max[u] = max(Max[u], S[u] - (S[v] - Max[v]));
    }
  }
}

int main() {
  string s;
  cin >> s;
  int N = (int)s.size();
  stack<int> st;
  for (int i = 0; i < N; i++) {
    if (i + 2 < N && s[i] == 'm' && s[i + 1] == 'i' && s[i + 2] == 'n') {
      st.push((int)g.size());
      g.push_back({});
      t.push_back(1);
    } else if (i + 2 < N && s[i] == 'm' && s[i + 1] == 'a' && s[i + 2] == 'x') {
      st.push((int)g.size());
      g.push_back({});
      t.push_back(2);
    } else if (s[i] == '?') {
      g[st.top()].push_back((int)g.size());
      g.push_back({});
      t.push_back(3);
    } else if (s[i] == ')') {
      int x = st.top();
      st.pop();
      if (!st.empty()) {
        g[st.top()].push_back(x);
      }
    }
  }
  S = Min = Max = vector<int>(g.size());
  DFS(0);
  cout << Max[0] - Min[0] + 1 << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 296 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 202084 KB Output is correct
2 Correct 400 ms 202136 KB Output is correct
3 Correct 399 ms 202132 KB Output is correct
4 Correct 431 ms 202148 KB Output is correct
5 Correct 420 ms 202048 KB Output is correct
6 Correct 398 ms 202040 KB Output is correct
7 Correct 401 ms 202160 KB Output is correct
8 Correct 402 ms 202100 KB Output is correct
9 Correct 396 ms 202152 KB Output is correct
10 Correct 418 ms 202120 KB Output is correct
11 Correct 417 ms 202096 KB Output is correct
12 Correct 470 ms 202112 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 296 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 432 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 428 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 2 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 432 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 428 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 428 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 432 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 468 KB Output is correct
82 Correct 1 ms 468 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 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 296 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 403 ms 202084 KB Output is correct
58 Correct 400 ms 202136 KB Output is correct
59 Correct 399 ms 202132 KB Output is correct
60 Correct 431 ms 202148 KB Output is correct
61 Correct 420 ms 202048 KB Output is correct
62 Correct 398 ms 202040 KB Output is correct
63 Correct 401 ms 202160 KB Output is correct
64 Correct 402 ms 202100 KB Output is correct
65 Correct 396 ms 202152 KB Output is correct
66 Correct 418 ms 202120 KB Output is correct
67 Correct 417 ms 202096 KB Output is correct
68 Correct 470 ms 202112 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 432 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 428 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 2 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 432 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 428 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 428 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 432 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 468 KB Output is correct
95 Correct 1 ms 468 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 388 ms 123496 KB Output is correct
101 Correct 387 ms 123464 KB Output is correct
102 Correct 366 ms 123464 KB Output is correct
103 Correct 359 ms 123560 KB Output is correct
104 Correct 373 ms 123520 KB Output is correct
105 Correct 386 ms 149708 KB Output is correct
106 Correct 377 ms 149696 KB Output is correct
107 Correct 368 ms 149792 KB Output is correct
108 Correct 388 ms 149676 KB Output is correct
109 Correct 376 ms 149788 KB Output is correct
110 Correct 385 ms 123504 KB Output is correct
111 Correct 382 ms 123468 KB Output is correct
112 Correct 358 ms 123516 KB Output is correct
113 Correct 370 ms 123560 KB Output is correct
114 Correct 364 ms 123516 KB Output is correct
115 Correct 402 ms 202296 KB Output is correct
116 Correct 445 ms 202144 KB Output is correct
117 Correct 426 ms 202148 KB Output is correct
118 Correct 395 ms 202068 KB Output is correct
119 Correct 413 ms 202148 KB Output is correct
120 Correct 384 ms 123632 KB Output is correct
121 Correct 365 ms 123576 KB Output is correct
122 Correct 424 ms 123460 KB Output is correct
123 Correct 390 ms 123540 KB Output is correct
124 Correct 365 ms 164688 KB Output is correct
125 Correct 362 ms 164900 KB Output is correct
126 Correct 353 ms 164760 KB Output is correct
127 Correct 366 ms 164784 KB Output is correct
128 Correct 202 ms 64808 KB Output is correct
129 Correct 191 ms 64904 KB Output is correct
130 Correct 187 ms 64984 KB Output is correct
131 Correct 1 ms 212 KB Output is correct