답안 #971595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971595 2024-04-29T04:02:36 Z nguyentunglam Homework (CEOI22_homework) C++17
100 / 100
89 ms 114896 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 2e6 + 10;

pair<int, int> st[N];

int t[N];

int operation[N];

int child[2][N], sz[N];

int l[N], r[N];

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  string str; cin >> str;


  int p = 0;

  int id = 0, _id = 0;

  for(char c : str) if (c == '?') _id++;
  int n = _id;

  for(int i = 0; i < str.size(); i++) {
    if (str[i] == 'm') {
      i += 3;
      st[++p] = make_pair(0, 0);
      t[p] = str[i - 1] == 'x';
//      cout << str[i - 1] << " " << t[p] << endl;
    }
    else if (str[i] == '?') {
      ++id;
      if (st[p].first == 0) st[p].first = id;
      else st[p].second = id;
    }
    else if (str[i] == ')') {
      ++_id;
      assert(st[p].first && st[p].second);
      child[0][_id] = st[p].first;
      child[1][_id] = st[p].second;
      operation[_id] = t[p];
//      cout << _id << " " << st[p].first << " " << st[p].second << " " << operation[_id] << endl;
      --p;
      if (st[p].first == 0) st[p].first = _id;
      else st[p].second = _id;
    }
  }

  auto dfs = [&] (auto self, int u) {
    if (u <= n) {
      l[u] = r[u] = sz[u] = 1;
      return;
    }
    int x0 = child[0][u], x1 = child[1][u];
    self(self, x1);
    self(self, x0);
    sz[u] = sz[x0] + sz[x1];
    if (operation[u]) {
      r[u] = max(sz[x0] + r[x1], sz[x1] + r[x0]);
      l[u] = l[x0] + l[x1];
    }
    else {
      l[u] = min(l[x0], l[x1]);
      r[u] = r[x0] + r[x1] - 1;
    }
    assert(l[u] <= r[u]);
  };

  dfs(dfs, _id);
  cout << r[_id] - l[_id] + 1;
}



Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i = 0; i < str.size(); i++) {
      |                  ~~^~~~~~~~~~~~
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14816 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 5 ms 14796 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 2 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14812 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14796 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14816 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 5 ms 14796 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 2 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14812 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14796 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 2 ms 14684 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 14684 KB Output is correct
33 Correct 2 ms 14684 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 2 ms 14684 KB Output is correct
38 Correct 2 ms 14808 KB Output is correct
39 Correct 2 ms 14684 KB Output is correct
40 Correct 2 ms 14816 KB Output is correct
41 Correct 2 ms 14684 KB Output is correct
42 Correct 3 ms 14684 KB Output is correct
43 Correct 2 ms 14684 KB Output is correct
44 Correct 2 ms 14796 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
46 Correct 2 ms 14896 KB Output is correct
47 Correct 3 ms 14684 KB Output is correct
48 Correct 2 ms 14684 KB Output is correct
49 Correct 2 ms 14936 KB Output is correct
50 Correct 2 ms 14680 KB Output is correct
51 Correct 2 ms 14680 KB Output is correct
52 Correct 2 ms 14804 KB Output is correct
53 Correct 2 ms 14684 KB Output is correct
54 Correct 2 ms 14684 KB Output is correct
55 Correct 2 ms 14684 KB Output is correct
56 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 113484 KB Output is correct
2 Correct 81 ms 113368 KB Output is correct
3 Correct 79 ms 114124 KB Output is correct
4 Correct 81 ms 114384 KB Output is correct
5 Correct 80 ms 113392 KB Output is correct
6 Correct 76 ms 114472 KB Output is correct
7 Correct 78 ms 113500 KB Output is correct
8 Correct 79 ms 113352 KB Output is correct
9 Correct 76 ms 114896 KB Output is correct
10 Correct 75 ms 113196 KB Output is correct
11 Correct 75 ms 113392 KB Output is correct
12 Correct 78 ms 113676 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14816 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 5 ms 14796 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 2 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14812 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14796 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 2 ms 14684 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 14684 KB Output is correct
33 Correct 2 ms 14684 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 2 ms 14684 KB Output is correct
38 Correct 2 ms 14808 KB Output is correct
39 Correct 2 ms 14684 KB Output is correct
40 Correct 2 ms 14816 KB Output is correct
41 Correct 2 ms 14684 KB Output is correct
42 Correct 3 ms 14684 KB Output is correct
43 Correct 2 ms 14684 KB Output is correct
44 Correct 2 ms 14796 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
46 Correct 2 ms 14896 KB Output is correct
47 Correct 3 ms 14684 KB Output is correct
48 Correct 2 ms 14684 KB Output is correct
49 Correct 2 ms 14936 KB Output is correct
50 Correct 2 ms 14680 KB Output is correct
51 Correct 2 ms 14680 KB Output is correct
52 Correct 2 ms 14804 KB Output is correct
53 Correct 2 ms 14684 KB Output is correct
54 Correct 2 ms 14684 KB Output is correct
55 Correct 2 ms 14684 KB Output is correct
56 Correct 2 ms 14684 KB Output is correct
57 Correct 2 ms 14680 KB Output is correct
58 Correct 2 ms 14684 KB Output is correct
59 Correct 2 ms 14804 KB Output is correct
60 Correct 2 ms 14680 KB Output is correct
61 Correct 2 ms 14684 KB Output is correct
62 Correct 2 ms 14680 KB Output is correct
63 Correct 2 ms 14684 KB Output is correct
64 Correct 2 ms 14684 KB Output is correct
65 Correct 2 ms 14684 KB Output is correct
66 Correct 2 ms 14684 KB Output is correct
67 Correct 2 ms 14684 KB Output is correct
68 Correct 2 ms 14684 KB Output is correct
69 Correct 2 ms 14684 KB Output is correct
70 Correct 2 ms 14684 KB Output is correct
71 Correct 2 ms 14684 KB Output is correct
72 Correct 2 ms 14684 KB Output is correct
73 Correct 2 ms 14684 KB Output is correct
74 Correct 2 ms 14684 KB Output is correct
75 Correct 2 ms 14880 KB Output is correct
76 Correct 2 ms 14684 KB Output is correct
77 Correct 2 ms 14808 KB Output is correct
78 Correct 2 ms 14684 KB Output is correct
79 Correct 2 ms 14804 KB Output is correct
80 Correct 2 ms 14800 KB Output is correct
81 Correct 2 ms 14684 KB Output is correct
82 Correct 2 ms 14684 KB Output is correct
83 Correct 2 ms 14792 KB Output is correct
84 Correct 2 ms 14684 KB Output is correct
85 Correct 2 ms 14684 KB Output is correct
86 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 3 ms 14816 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 5 ms 14796 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 2 ms 14684 KB Output is correct
16 Correct 2 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14812 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14796 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 2 ms 14684 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 14684 KB Output is correct
33 Correct 2 ms 14684 KB Output is correct
34 Correct 2 ms 14684 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 2 ms 14684 KB Output is correct
38 Correct 2 ms 14808 KB Output is correct
39 Correct 2 ms 14684 KB Output is correct
40 Correct 2 ms 14816 KB Output is correct
41 Correct 2 ms 14684 KB Output is correct
42 Correct 3 ms 14684 KB Output is correct
43 Correct 2 ms 14684 KB Output is correct
44 Correct 2 ms 14796 KB Output is correct
45 Correct 2 ms 14940 KB Output is correct
46 Correct 2 ms 14896 KB Output is correct
47 Correct 3 ms 14684 KB Output is correct
48 Correct 2 ms 14684 KB Output is correct
49 Correct 2 ms 14936 KB Output is correct
50 Correct 2 ms 14680 KB Output is correct
51 Correct 2 ms 14680 KB Output is correct
52 Correct 2 ms 14804 KB Output is correct
53 Correct 2 ms 14684 KB Output is correct
54 Correct 2 ms 14684 KB Output is correct
55 Correct 2 ms 14684 KB Output is correct
56 Correct 2 ms 14684 KB Output is correct
57 Correct 89 ms 113484 KB Output is correct
58 Correct 81 ms 113368 KB Output is correct
59 Correct 79 ms 114124 KB Output is correct
60 Correct 81 ms 114384 KB Output is correct
61 Correct 80 ms 113392 KB Output is correct
62 Correct 76 ms 114472 KB Output is correct
63 Correct 78 ms 113500 KB Output is correct
64 Correct 79 ms 113352 KB Output is correct
65 Correct 76 ms 114896 KB Output is correct
66 Correct 75 ms 113196 KB Output is correct
67 Correct 75 ms 113392 KB Output is correct
68 Correct 78 ms 113676 KB Output is correct
69 Correct 2 ms 14684 KB Output is correct
70 Correct 2 ms 14680 KB Output is correct
71 Correct 2 ms 14684 KB Output is correct
72 Correct 2 ms 14804 KB Output is correct
73 Correct 2 ms 14680 KB Output is correct
74 Correct 2 ms 14684 KB Output is correct
75 Correct 2 ms 14680 KB Output is correct
76 Correct 2 ms 14684 KB Output is correct
77 Correct 2 ms 14684 KB Output is correct
78 Correct 2 ms 14684 KB Output is correct
79 Correct 2 ms 14684 KB Output is correct
80 Correct 2 ms 14684 KB Output is correct
81 Correct 2 ms 14684 KB Output is correct
82 Correct 2 ms 14684 KB Output is correct
83 Correct 2 ms 14684 KB Output is correct
84 Correct 2 ms 14684 KB Output is correct
85 Correct 2 ms 14684 KB Output is correct
86 Correct 2 ms 14684 KB Output is correct
87 Correct 2 ms 14684 KB Output is correct
88 Correct 2 ms 14880 KB Output is correct
89 Correct 2 ms 14684 KB Output is correct
90 Correct 2 ms 14808 KB Output is correct
91 Correct 2 ms 14684 KB Output is correct
92 Correct 2 ms 14804 KB Output is correct
93 Correct 2 ms 14800 KB Output is correct
94 Correct 2 ms 14684 KB Output is correct
95 Correct 2 ms 14684 KB Output is correct
96 Correct 2 ms 14792 KB Output is correct
97 Correct 2 ms 14684 KB Output is correct
98 Correct 2 ms 14684 KB Output is correct
99 Correct 2 ms 14684 KB Output is correct
100 Correct 48 ms 54780 KB Output is correct
101 Correct 47 ms 54740 KB Output is correct
102 Correct 41 ms 54184 KB Output is correct
103 Correct 44 ms 54432 KB Output is correct
104 Correct 40 ms 54224 KB Output is correct
105 Correct 59 ms 74768 KB Output is correct
106 Correct 60 ms 73936 KB Output is correct
107 Correct 56 ms 75228 KB Output is correct
108 Correct 56 ms 74960 KB Output is correct
109 Correct 56 ms 73932 KB Output is correct
110 Correct 53 ms 55244 KB Output is correct
111 Correct 49 ms 54064 KB Output is correct
112 Correct 51 ms 55128 KB Output is correct
113 Correct 45 ms 54228 KB Output is correct
114 Correct 44 ms 54484 KB Output is correct
115 Correct 89 ms 112216 KB Output is correct
116 Correct 79 ms 112140 KB Output is correct
117 Correct 79 ms 109064 KB Output is correct
118 Correct 79 ms 109820 KB Output is correct
119 Correct 77 ms 108564 KB Output is correct
120 Correct 44 ms 51408 KB Output is correct
121 Correct 43 ms 51696 KB Output is correct
122 Correct 46 ms 50636 KB Output is correct
123 Correct 47 ms 51044 KB Output is correct
124 Correct 51 ms 80748 KB Output is correct
125 Correct 56 ms 81096 KB Output is correct
126 Correct 54 ms 80076 KB Output is correct
127 Correct 52 ms 80856 KB Output is correct
128 Correct 20 ms 37088 KB Output is correct
129 Correct 18 ms 37092 KB Output is correct
130 Correct 17 ms 37092 KB Output is correct
131 Correct 2 ms 14684 KB Output is correct