답안 #1006360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006360 2024-06-23T20:41:19 Z aykhn Homework (CEOI22_homework) C++17
100 / 100
153 ms 181572 KB
#include <bits/stdc++.h>
 
using namespace std;

#define inf 0x3F3F3F3F

const int MXN = 5e6 + 5;

int n, r, cnt;
string s;
int adj[MXN][2];
array<int, 2> dp[MXN];
int sz[MXN];
int t[MXN];
vector<int> R; 

array<int, 2> MERGE(array<int, 2> x, array<int, 2> y)
{
  return {min(x[0], y[0]), max(x[1], y[1])};
}

void dfs(int a)
{
  if (t[a] == 2)
  {
    dp[a] = {1, 1};
    sz[a] = 1;
    return;
  }
  dfs(adj[a][0]), dfs(adj[a][1]);
  if (t[a] == 1)
  {
    dp[a] = MERGE({dp[adj[a][0]][0] + dp[adj[a][1]][0], dp[adj[a][0]][1] + sz[adj[a][1]]}, {dp[adj[a][1]][0] + dp[adj[a][0]][0], dp[adj[a][1]][1] + sz[adj[a][0]]});
  }
  else
  {
    dp[a] = MERGE({dp[adj[a][0]][0], dp[adj[a][0]][1] + dp[adj[a][1]][1] - 1}, {dp[adj[a][1]][0], dp[adj[a][1]][1] + dp[adj[a][0]][1] - 1});
  }
  sz[a] = sz[adj[a][0]] + sz[adj[a][1]];
}

signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  n = s.length();
  string nw;
  for (int i = 0; i < s.length(); i++)
  {
    if (s[i] == ',') continue;
    if (s[i] == '?')
    {
      t[nw.size()] = 2;
      nw.push_back('(');
      nw.push_back(')');
    }
    else if (s[i] == '(' || s[i] == ')') nw.push_back(s[i]);
    else 
    {
      if (s[i + 1] == 'i') t[nw.size()] = 0;
      else t[nw.size()] = 1;
      i += 2;
    }
  }
  vector<int> v;
  R.assign(nw.size(), 0);
  for (int i = (int)nw.size() - 1; i >= 0; i--)
  {
    if (nw[i] == ')') v.push_back(i);
    else R[i] = v.back(), v.pop_back();
  }
  v.clear();
  for (int i = (int)nw.size() - 1; i >= 0; i--)
  {
    if (nw[i] == '(') 
    {
      vector<int> tmp;
      while (!v.empty() && v.back() <= R[i]) tmp.push_back(v.back()), v.pop_back();
      assert(tmp.size() == 2 || tmp.empty());
      v.push_back(i);
      if (tmp.size() == 2) 
      {
        adj[i][0] = tmp[0], adj[i][1] = tmp[1];
      }
    }
  }
  assert(v.size() == 1);
  dfs(v[0]);
  cout << dp[v[0]][1] - dp[v[0]][0] + 1 << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i = 0; i < s.length(); i++)
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6576 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6576 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6616 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6608 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 0 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 0 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 172936 KB Output is correct
2 Correct 153 ms 180380 KB Output is correct
3 Correct 143 ms 180200 KB Output is correct
4 Correct 153 ms 179920 KB Output is correct
5 Correct 148 ms 179664 KB Output is correct
6 Correct 146 ms 181572 KB Output is correct
7 Correct 133 ms 178780 KB Output is correct
8 Correct 144 ms 180176 KB Output is correct
9 Correct 138 ms 178640 KB Output is correct
10 Correct 142 ms 180432 KB Output is correct
11 Correct 144 ms 180176 KB Output is correct
12 Correct 148 ms 179256 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6576 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6616 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6608 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 0 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 0 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 1 ms 8536 KB Output is correct
58 Correct 1 ms 8540 KB Output is correct
59 Correct 1 ms 8540 KB Output is correct
60 Correct 1 ms 8540 KB Output is correct
61 Correct 1 ms 8540 KB Output is correct
62 Correct 1 ms 8540 KB Output is correct
63 Correct 1 ms 8792 KB Output is correct
64 Correct 1 ms 8540 KB Output is correct
65 Correct 1 ms 8540 KB Output is correct
66 Correct 1 ms 8540 KB Output is correct
67 Correct 1 ms 8540 KB Output is correct
68 Correct 1 ms 8540 KB Output is correct
69 Correct 1 ms 8540 KB Output is correct
70 Correct 1 ms 8540 KB Output is correct
71 Correct 1 ms 8540 KB Output is correct
72 Correct 1 ms 8540 KB Output is correct
73 Correct 1 ms 8540 KB Output is correct
74 Correct 1 ms 8540 KB Output is correct
75 Correct 1 ms 8540 KB Output is correct
76 Correct 1 ms 8540 KB Output is correct
77 Correct 1 ms 8540 KB Output is correct
78 Correct 1 ms 8540 KB Output is correct
79 Correct 1 ms 8540 KB Output is correct
80 Correct 1 ms 8540 KB Output is correct
81 Correct 1 ms 8540 KB Output is correct
82 Correct 1 ms 8540 KB Output is correct
83 Correct 1 ms 6492 KB Output is correct
84 Correct 1 ms 6492 KB Output is correct
85 Correct 1 ms 6492 KB Output is correct
86 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6576 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6616 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6608 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 0 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 0 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 136 ms 172936 KB Output is correct
58 Correct 153 ms 180380 KB Output is correct
59 Correct 143 ms 180200 KB Output is correct
60 Correct 153 ms 179920 KB Output is correct
61 Correct 148 ms 179664 KB Output is correct
62 Correct 146 ms 181572 KB Output is correct
63 Correct 133 ms 178780 KB Output is correct
64 Correct 144 ms 180176 KB Output is correct
65 Correct 138 ms 178640 KB Output is correct
66 Correct 142 ms 180432 KB Output is correct
67 Correct 144 ms 180176 KB Output is correct
68 Correct 148 ms 179256 KB Output is correct
69 Correct 1 ms 6492 KB Output is correct
70 Correct 1 ms 8536 KB Output is correct
71 Correct 1 ms 8540 KB Output is correct
72 Correct 1 ms 8540 KB Output is correct
73 Correct 1 ms 8540 KB Output is correct
74 Correct 1 ms 8540 KB Output is correct
75 Correct 1 ms 8540 KB Output is correct
76 Correct 1 ms 8792 KB Output is correct
77 Correct 1 ms 8540 KB Output is correct
78 Correct 1 ms 8540 KB Output is correct
79 Correct 1 ms 8540 KB Output is correct
80 Correct 1 ms 8540 KB Output is correct
81 Correct 1 ms 8540 KB Output is correct
82 Correct 1 ms 8540 KB Output is correct
83 Correct 1 ms 8540 KB Output is correct
84 Correct 1 ms 8540 KB Output is correct
85 Correct 1 ms 8540 KB Output is correct
86 Correct 1 ms 8540 KB Output is correct
87 Correct 1 ms 8540 KB Output is correct
88 Correct 1 ms 8540 KB Output is correct
89 Correct 1 ms 8540 KB Output is correct
90 Correct 1 ms 8540 KB Output is correct
91 Correct 1 ms 8540 KB Output is correct
92 Correct 1 ms 8540 KB Output is correct
93 Correct 1 ms 8540 KB Output is correct
94 Correct 1 ms 8540 KB Output is correct
95 Correct 1 ms 8540 KB Output is correct
96 Correct 1 ms 6492 KB Output is correct
97 Correct 1 ms 6492 KB Output is correct
98 Correct 1 ms 6492 KB Output is correct
99 Correct 1 ms 6488 KB Output is correct
100 Correct 112 ms 145068 KB Output is correct
101 Correct 125 ms 144336 KB Output is correct
102 Correct 101 ms 146128 KB Output is correct
103 Correct 107 ms 146384 KB Output is correct
104 Correct 111 ms 146604 KB Output is correct
105 Correct 117 ms 161492 KB Output is correct
106 Correct 128 ms 161248 KB Output is correct
107 Correct 121 ms 161372 KB Output is correct
108 Correct 127 ms 160448 KB Output is correct
109 Correct 119 ms 162512 KB Output is correct
110 Correct 114 ms 145980 KB Output is correct
111 Correct 110 ms 146300 KB Output is correct
112 Correct 108 ms 146128 KB Output is correct
113 Correct 106 ms 146768 KB Output is correct
114 Correct 102 ms 145872 KB Output is correct
115 Correct 140 ms 179664 KB Output is correct
116 Correct 147 ms 180304 KB Output is correct
117 Correct 137 ms 181096 KB Output is correct
118 Correct 134 ms 180176 KB Output is correct
119 Correct 139 ms 179664 KB Output is correct
120 Correct 108 ms 145092 KB Output is correct
121 Correct 115 ms 144100 KB Output is correct
122 Correct 131 ms 145324 KB Output is correct
123 Correct 118 ms 144244 KB Output is correct
124 Correct 117 ms 157904 KB Output is correct
125 Correct 113 ms 156880 KB Output is correct
126 Correct 136 ms 158308 KB Output is correct
127 Correct 117 ms 155432 KB Output is correct
128 Correct 52 ms 78544 KB Output is correct
129 Correct 53 ms 78036 KB Output is correct
130 Correct 49 ms 78036 KB Output is correct
131 Correct 1 ms 6492 KB Output is correct