Submission #731221

# Submission time Handle Problem Language Result Execution time Memory
731221 2023-04-27T07:34:59 Z erray Homework (CEOI22_homework) C++11
100 / 100
256 ms 199028 KB
//author: erray
#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> string to_string(pair<A, B>);
template<typename A, typename B, typename C> string to_string(tuple<A, B, C>);
string to_string(string s) {
  return '"' + s + '"';
}
string to_string(const char* c) {
  return to_string(string(c));
}
string to_string(char c) {
  return string("'") + c + "'";
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template<size_t T> 
string to_string(bitset<T> bs) {
  return bs.to_string();
}
template<typename T>
string to_string(priority_queue<T> pq) {
  vector<T> a;
  while (!pq.empty()) {
    a.push_back(pq.top());
    pq.pop();
  }
  return to_string(a);
}
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < int(v.size()); ++i) {
    if (int(res.size()) > 1) {
      res += ", ";
    }
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template<typename T> 
string to_string(T v) {
  string res = "{";
  for (auto x : v) {
    if (int(res.size()) > 1) {
      res += ", ";
    }
    res += to_string(x);
  }
  res += "}";
  return res;
}
template<typename A, typename B> string to_string(pair<A, B> p) {
  return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
template<typename A, typename B, typename C> string to_string(tuple<A, B, C> t) {
  return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ')';
}
void debug_out() {
  cerr << endl;
}
template<typename H, typename... T> 
void debug_out(H head, T... tail) {
  cerr << "  " << to_string(head);
  debug_out(tail...);
}

#ifdef DEBUG 
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else 
  #define debug(...) void(37)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int s = int(S.size());
  int n = count(S.begin(), S.end(), 'm') + count(S.begin(), S.end(), '?');
  vector<vector<int>> g(n);
  vector<int> last(2 * s + 2, -1);
  vector<int> id(s, -1);
  vector<int> type(n);
  int sum = 0;
  int t = n - 1;
  for (int i = s - 1; i >= 0; --i) {
    debug(i, S[i], sum);
    if (S[i] == 'm') {
      id[i] = t--;
      type[id[i]] = (S[i + 1] == 'a');      
      g[id[i]].push_back(id[i + 4]);
      assert(last[sum + s + 1] != -1);
      g[id[i]].push_back(last[sum + s + 1]);
    } else if (S[i] == ',') {
      debug(sum, id[i + 1]);
      last[sum + s] = id[i + 1];
    } else if (S[i] == '?') {
      id[i] = t--;
    } else if (S[i] == '(') {
      sum -= 1;
    } else if (S[i] == ')') {
      sum += 1;
    }
  }
  vector<int> size(n);
  vector<int> l(n, 0);
  vector<int> r(n, 0);
  for (int i = n - 1; i >= 0; --i) {
    if (g[i].empty()) {
      size[i] = 1;
      continue;
    }
    int x = g[i][0], y = g[i][1];
    size[i] += size[x] + size[y];
    debug(i, size[i], x, y);
    if (size[i] == 2) {
      if (type[i]) {
        l[i] = 1;
      } else {
        r[i] = 1;
      }
    } else if (type[i]) {
      r[i] = min(r[x], r[y]);
      l[i] = l[x] + l[y] + 1;//?
    } else {
      l[i] = min(l[x], l[y]);
      r[i] = r[x] + r[y] + 1;
    }
  }
  cout << size[0] - l[0] - r[0] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 256 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 256 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 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 0 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 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 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 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 198964 KB Output is correct
2 Correct 198 ms 198880 KB Output is correct
3 Correct 217 ms 198968 KB Output is correct
4 Correct 213 ms 198852 KB Output is correct
5 Correct 209 ms 198952 KB Output is correct
6 Correct 191 ms 198872 KB Output is correct
7 Correct 209 ms 198848 KB Output is correct
8 Correct 204 ms 198984 KB Output is correct
9 Correct 205 ms 199028 KB Output is correct
10 Correct 204 ms 198948 KB Output is correct
11 Correct 191 ms 198848 KB Output is correct
12 Correct 186 ms 198920 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 256 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 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 0 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 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 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 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 1 ms 468 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 468 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 0 ms 468 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 0 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 256 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 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 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 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 0 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 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 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 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 211 ms 198964 KB Output is correct
58 Correct 198 ms 198880 KB Output is correct
59 Correct 217 ms 198968 KB Output is correct
60 Correct 213 ms 198852 KB Output is correct
61 Correct 209 ms 198952 KB Output is correct
62 Correct 191 ms 198872 KB Output is correct
63 Correct 209 ms 198848 KB Output is correct
64 Correct 204 ms 198984 KB Output is correct
65 Correct 205 ms 199028 KB Output is correct
66 Correct 204 ms 198948 KB Output is correct
67 Correct 191 ms 198848 KB Output is correct
68 Correct 186 ms 198920 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 1 ms 468 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 468 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 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 468 KB Output is correct
84 Correct 1 ms 468 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 468 KB Output is correct
91 Correct 1 ms 468 KB Output is correct
92 Correct 1 ms 468 KB Output is correct
93 Correct 0 ms 468 KB Output is correct
94 Correct 1 ms 468 KB Output is correct
95 Correct 0 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 0 ms 212 KB Output is correct
100 Correct 213 ms 198852 KB Output is correct
101 Correct 215 ms 198964 KB Output is correct
102 Correct 250 ms 198912 KB Output is correct
103 Correct 193 ms 198964 KB Output is correct
104 Correct 198 ms 198960 KB Output is correct
105 Correct 212 ms 198964 KB Output is correct
106 Correct 203 ms 198888 KB Output is correct
107 Correct 200 ms 198836 KB Output is correct
108 Correct 199 ms 198876 KB Output is correct
109 Correct 208 ms 198956 KB Output is correct
110 Correct 218 ms 198960 KB Output is correct
111 Correct 208 ms 198904 KB Output is correct
112 Correct 210 ms 198924 KB Output is correct
113 Correct 200 ms 198964 KB Output is correct
114 Correct 213 ms 198852 KB Output is correct
115 Correct 205 ms 198972 KB Output is correct
116 Correct 204 ms 198852 KB Output is correct
117 Correct 203 ms 198960 KB Output is correct
118 Correct 208 ms 198924 KB Output is correct
119 Correct 196 ms 198844 KB Output is correct
120 Correct 213 ms 198856 KB Output is correct
121 Correct 202 ms 198924 KB Output is correct
122 Correct 222 ms 198852 KB Output is correct
123 Correct 256 ms 198968 KB Output is correct
124 Correct 188 ms 198896 KB Output is correct
125 Correct 210 ms 198936 KB Output is correct
126 Correct 192 ms 198908 KB Output is correct
127 Correct 189 ms 198952 KB Output is correct
128 Correct 108 ms 104524 KB Output is correct
129 Correct 105 ms 104448 KB Output is correct
130 Correct 102 ms 104404 KB Output is correct
131 Correct 0 ms 212 KB Output is correct