답안 #734524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734524 2023-05-02T15:04:17 Z danikoynov Homework (CEOI22_homework) C++14
100 / 100
290 ms 112044 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

struct node
{
    int left, right;
    int type; /// 0 - ?; 1 - min; 2 - max;

    int lb, rb, sub;
    node()
    {
        left = -1;
        right = -1;
        type = -1;
        sub = 0;
        lb = 1e9;
        rb = -1e9;
        sub = 0;
    }
};

const int maxn = 2e6 + 10;

node tree[maxn];
string s;
int last_node;
void create_tree()
{
    int len = s.size();

    stack < int > st;
    int i = 0;
    while(i < len)
    {
        ///cout << i << endl;
        if (s[i] == 'm')
        {
            ++ last_node;
            if (!st.empty())
            {   ///cout << "here " << i << endl;
                int ver = st.top();///cout << ver << " : " << tree[ver].left << endl;
                if (tree[ver].left == -1)
                    tree[ver].left = last_node;
                else
                if (tree[ver].right == -1)
                {
                    ///cout << "yep" << endl;
                    tree[ver].right = last_node;
                }
            }
            if (s[i + 1] == 'i')
                tree[last_node].type = 1;
            else
                tree[last_node].type = 2;
            st.push(last_node);
            i += 4;
        }
        else
        if (s[i] == '?')
        {

            ++ last_node;
            tree[last_node].sub = 1;
            if (!st.empty())
            {
                int ver = st.top();

                if (tree[ver].left == -1)
                    tree[ver].left = last_node;
                else
                if (tree[ver].right == -1)
                {
                    ///cout << "wow " << ver << endl;
                    tree[ver].right = last_node;
                }
            }
            tree[last_node].type = 0;
            i ++;
        }
        else
        {
            i ++;
        }
        while(!st.empty() && tree[st.top()].right != -1 &&
              tree[st.top()].left != -1)
                st.pop();
    }
}

void dfs(int v)
{
    ///cout << v << " : " << tree[v].type <<  " " << tree[v].left << " " << tree[v].right <<endl;
    if (tree[v].left == -1)
    {
        tree[v].lb = tree[v].rb = 1;
        return;
    }

    int left_child = tree[v].left;
    int right_child = tree[v].right;
        dfs(left_child);
        dfs(right_child);

    tree[v].sub = tree[left_child].sub + tree[right_child].sub;
    if (tree[v].type == 1)
    {
        tree[v].lb = min(tree[left_child].lb, tree[right_child].lb);
        tree[v].rb = tree[left_child].rb + tree[right_child].rb - 1;

        /**for (int x = 1; x <= tree[v].sub; x ++)
        {
            bool found = false;
            ///cout << v << " : " << x << " " << tree[left_child].lb << " " << tree[right_child].rb << endl;
            if ((x >= tree[left_child].lb || x >= tree[right_child].lb) &&
                x < tree[left_child].rb + tree[right_child].rb)
                    found = true;
            //if (x >= tree[right_child].lb &&
              //  (tree[v].sub - x) > (tree[left_child].sub - tree[left_child].rb))
                //    found = true;
            if (found)
            {
                //cout << "found" << endl;
                tree[v].rb = x;
                tree[v].lb = min(tree[v].lb, x);
            }
        }*/

        ///cout << v << " " << tree[v].lb << " " << tree[v].rb << endl;
    }
    else
    {
        tree[v].rb = tree[v].sub + max(tree[left_child].rb - tree[left_child].sub,
                                            tree[right_child].rb - tree[right_child].sub);
                                            ///cout << tree[v].rb << endl;
        tree[v].lb = tree[left_child].lb - tree[left_child].sub + tree[right_child].lb - tree[right_child].sub  + tree[v].sub;
        ///cout << tree[v].lb << endl;
        /**for (int x = 1; x <= tree[v].sub; x ++)
        {
            bool found = false;
            if ((tree[v].sub - x >= tree[left_child].sub - tree[left_child].rb ||
                 tree[v].sub - x >= tree[right_child].sub - tree[right_child].rb) &&
                tree[v].sub - x < tree[left_child].sub - tree[left_child].lb +
                                tree[right_child].sub - tree[right_child].lb + 1)
                                    found = true;
            if (found)
            {
                //tree[v].rb = x;
                //cout << "pos " << x << endl;
                ///tree[v].lb = min(tree[v].lb, x);
            }
        }*/
    }

}
void solve()
{
    cin >> s;
    create_tree();
    dfs(1);
    cout << tree[1].rb - tree[1].lb + 1 << endl;

}

int main()
{
    solve();
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 24 ms 47152 KB Output is correct
3 Correct 22 ms 47156 KB Output is correct
4 Correct 23 ms 47208 KB Output is correct
5 Correct 31 ms 47192 KB Output is correct
6 Correct 25 ms 47252 KB Output is correct
7 Correct 30 ms 47128 KB Output is correct
8 Correct 24 ms 47136 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 25 ms 47188 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47156 KB Output is correct
14 Correct 23 ms 47188 KB Output is correct
15 Correct 24 ms 47188 KB Output is correct
16 Correct 27 ms 47248 KB Output is correct
17 Correct 24 ms 47280 KB Output is correct
18 Correct 27 ms 47264 KB Output is correct
19 Correct 25 ms 47260 KB Output is correct
20 Correct 23 ms 47188 KB Output is correct
21 Correct 23 ms 47184 KB Output is correct
22 Correct 24 ms 47196 KB Output is correct
23 Correct 25 ms 47204 KB Output is correct
24 Correct 23 ms 47212 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 22 ms 47220 KB Output is correct
27 Correct 24 ms 47180 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 24 ms 47152 KB Output is correct
3 Correct 22 ms 47156 KB Output is correct
4 Correct 23 ms 47208 KB Output is correct
5 Correct 31 ms 47192 KB Output is correct
6 Correct 25 ms 47252 KB Output is correct
7 Correct 30 ms 47128 KB Output is correct
8 Correct 24 ms 47136 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 25 ms 47188 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47156 KB Output is correct
14 Correct 23 ms 47188 KB Output is correct
15 Correct 24 ms 47188 KB Output is correct
16 Correct 27 ms 47248 KB Output is correct
17 Correct 24 ms 47280 KB Output is correct
18 Correct 27 ms 47264 KB Output is correct
19 Correct 25 ms 47260 KB Output is correct
20 Correct 23 ms 47188 KB Output is correct
21 Correct 23 ms 47184 KB Output is correct
22 Correct 24 ms 47196 KB Output is correct
23 Correct 25 ms 47204 KB Output is correct
24 Correct 23 ms 47212 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 22 ms 47220 KB Output is correct
27 Correct 24 ms 47180 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 24 ms 47208 KB Output is correct
30 Correct 23 ms 47236 KB Output is correct
31 Correct 24 ms 47180 KB Output is correct
32 Correct 24 ms 47168 KB Output is correct
33 Correct 23 ms 47268 KB Output is correct
34 Correct 24 ms 47124 KB Output is correct
35 Correct 23 ms 47184 KB Output is correct
36 Correct 27 ms 47200 KB Output is correct
37 Correct 25 ms 47188 KB Output is correct
38 Correct 25 ms 47232 KB Output is correct
39 Correct 23 ms 47188 KB Output is correct
40 Correct 26 ms 47208 KB Output is correct
41 Correct 24 ms 47232 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 24 ms 47264 KB Output is correct
44 Correct 24 ms 47184 KB Output is correct
45 Correct 25 ms 47232 KB Output is correct
46 Correct 24 ms 47188 KB Output is correct
47 Correct 24 ms 47152 KB Output is correct
48 Correct 24 ms 47156 KB Output is correct
49 Correct 23 ms 47260 KB Output is correct
50 Correct 23 ms 47248 KB Output is correct
51 Correct 28 ms 47188 KB Output is correct
52 Correct 24 ms 47312 KB Output is correct
53 Correct 24 ms 47188 KB Output is correct
54 Correct 24 ms 47144 KB Output is correct
55 Correct 25 ms 47260 KB Output is correct
56 Correct 24 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 105128 KB Output is correct
2 Correct 265 ms 111940 KB Output is correct
3 Correct 249 ms 111916 KB Output is correct
4 Correct 249 ms 112004 KB Output is correct
5 Correct 255 ms 112044 KB Output is correct
6 Correct 247 ms 111968 KB Output is correct
7 Correct 247 ms 111936 KB Output is correct
8 Correct 248 ms 112044 KB Output is correct
9 Correct 256 ms 111916 KB Output is correct
10 Correct 274 ms 112016 KB Output is correct
11 Correct 278 ms 111912 KB Output is correct
12 Correct 268 ms 112044 KB Output is correct
13 Correct 26 ms 47264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 24 ms 47152 KB Output is correct
3 Correct 22 ms 47156 KB Output is correct
4 Correct 23 ms 47208 KB Output is correct
5 Correct 31 ms 47192 KB Output is correct
6 Correct 25 ms 47252 KB Output is correct
7 Correct 30 ms 47128 KB Output is correct
8 Correct 24 ms 47136 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 25 ms 47188 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47156 KB Output is correct
14 Correct 23 ms 47188 KB Output is correct
15 Correct 24 ms 47188 KB Output is correct
16 Correct 27 ms 47248 KB Output is correct
17 Correct 24 ms 47280 KB Output is correct
18 Correct 27 ms 47264 KB Output is correct
19 Correct 25 ms 47260 KB Output is correct
20 Correct 23 ms 47188 KB Output is correct
21 Correct 23 ms 47184 KB Output is correct
22 Correct 24 ms 47196 KB Output is correct
23 Correct 25 ms 47204 KB Output is correct
24 Correct 23 ms 47212 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 22 ms 47220 KB Output is correct
27 Correct 24 ms 47180 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 24 ms 47208 KB Output is correct
30 Correct 23 ms 47236 KB Output is correct
31 Correct 24 ms 47180 KB Output is correct
32 Correct 24 ms 47168 KB Output is correct
33 Correct 23 ms 47268 KB Output is correct
34 Correct 24 ms 47124 KB Output is correct
35 Correct 23 ms 47184 KB Output is correct
36 Correct 27 ms 47200 KB Output is correct
37 Correct 25 ms 47188 KB Output is correct
38 Correct 25 ms 47232 KB Output is correct
39 Correct 23 ms 47188 KB Output is correct
40 Correct 26 ms 47208 KB Output is correct
41 Correct 24 ms 47232 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 24 ms 47264 KB Output is correct
44 Correct 24 ms 47184 KB Output is correct
45 Correct 25 ms 47232 KB Output is correct
46 Correct 24 ms 47188 KB Output is correct
47 Correct 24 ms 47152 KB Output is correct
48 Correct 24 ms 47156 KB Output is correct
49 Correct 23 ms 47260 KB Output is correct
50 Correct 23 ms 47248 KB Output is correct
51 Correct 28 ms 47188 KB Output is correct
52 Correct 24 ms 47312 KB Output is correct
53 Correct 24 ms 47188 KB Output is correct
54 Correct 24 ms 47144 KB Output is correct
55 Correct 25 ms 47260 KB Output is correct
56 Correct 24 ms 47188 KB Output is correct
57 Correct 23 ms 47208 KB Output is correct
58 Correct 26 ms 47188 KB Output is correct
59 Correct 29 ms 47228 KB Output is correct
60 Correct 22 ms 47188 KB Output is correct
61 Correct 22 ms 47200 KB Output is correct
62 Correct 20 ms 47212 KB Output is correct
63 Correct 23 ms 47272 KB Output is correct
64 Correct 22 ms 47200 KB Output is correct
65 Correct 22 ms 47196 KB Output is correct
66 Correct 22 ms 47188 KB Output is correct
67 Correct 21 ms 47188 KB Output is correct
68 Correct 21 ms 47264 KB Output is correct
69 Correct 21 ms 47236 KB Output is correct
70 Correct 21 ms 47176 KB Output is correct
71 Correct 22 ms 47252 KB Output is correct
72 Correct 21 ms 47220 KB Output is correct
73 Correct 21 ms 47316 KB Output is correct
74 Correct 20 ms 47240 KB Output is correct
75 Correct 21 ms 47308 KB Output is correct
76 Correct 20 ms 47316 KB Output is correct
77 Correct 21 ms 47192 KB Output is correct
78 Correct 21 ms 47188 KB Output is correct
79 Correct 21 ms 47188 KB Output is correct
80 Correct 20 ms 47188 KB Output is correct
81 Correct 23 ms 47288 KB Output is correct
82 Correct 24 ms 47284 KB Output is correct
83 Correct 25 ms 47132 KB Output is correct
84 Correct 24 ms 47232 KB Output is correct
85 Correct 23 ms 47204 KB Output is correct
86 Correct 26 ms 47216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 24 ms 47152 KB Output is correct
3 Correct 22 ms 47156 KB Output is correct
4 Correct 23 ms 47208 KB Output is correct
5 Correct 31 ms 47192 KB Output is correct
6 Correct 25 ms 47252 KB Output is correct
7 Correct 30 ms 47128 KB Output is correct
8 Correct 24 ms 47136 KB Output is correct
9 Correct 26 ms 47248 KB Output is correct
10 Correct 25 ms 47188 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47156 KB Output is correct
14 Correct 23 ms 47188 KB Output is correct
15 Correct 24 ms 47188 KB Output is correct
16 Correct 27 ms 47248 KB Output is correct
17 Correct 24 ms 47280 KB Output is correct
18 Correct 27 ms 47264 KB Output is correct
19 Correct 25 ms 47260 KB Output is correct
20 Correct 23 ms 47188 KB Output is correct
21 Correct 23 ms 47184 KB Output is correct
22 Correct 24 ms 47196 KB Output is correct
23 Correct 25 ms 47204 KB Output is correct
24 Correct 23 ms 47212 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 22 ms 47220 KB Output is correct
27 Correct 24 ms 47180 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 24 ms 47208 KB Output is correct
30 Correct 23 ms 47236 KB Output is correct
31 Correct 24 ms 47180 KB Output is correct
32 Correct 24 ms 47168 KB Output is correct
33 Correct 23 ms 47268 KB Output is correct
34 Correct 24 ms 47124 KB Output is correct
35 Correct 23 ms 47184 KB Output is correct
36 Correct 27 ms 47200 KB Output is correct
37 Correct 25 ms 47188 KB Output is correct
38 Correct 25 ms 47232 KB Output is correct
39 Correct 23 ms 47188 KB Output is correct
40 Correct 26 ms 47208 KB Output is correct
41 Correct 24 ms 47232 KB Output is correct
42 Correct 23 ms 47196 KB Output is correct
43 Correct 24 ms 47264 KB Output is correct
44 Correct 24 ms 47184 KB Output is correct
45 Correct 25 ms 47232 KB Output is correct
46 Correct 24 ms 47188 KB Output is correct
47 Correct 24 ms 47152 KB Output is correct
48 Correct 24 ms 47156 KB Output is correct
49 Correct 23 ms 47260 KB Output is correct
50 Correct 23 ms 47248 KB Output is correct
51 Correct 28 ms 47188 KB Output is correct
52 Correct 24 ms 47312 KB Output is correct
53 Correct 24 ms 47188 KB Output is correct
54 Correct 24 ms 47144 KB Output is correct
55 Correct 25 ms 47260 KB Output is correct
56 Correct 24 ms 47188 KB Output is correct
57 Correct 239 ms 105128 KB Output is correct
58 Correct 265 ms 111940 KB Output is correct
59 Correct 249 ms 111916 KB Output is correct
60 Correct 249 ms 112004 KB Output is correct
61 Correct 255 ms 112044 KB Output is correct
62 Correct 247 ms 111968 KB Output is correct
63 Correct 247 ms 111936 KB Output is correct
64 Correct 248 ms 112044 KB Output is correct
65 Correct 256 ms 111916 KB Output is correct
66 Correct 274 ms 112016 KB Output is correct
67 Correct 278 ms 111912 KB Output is correct
68 Correct 268 ms 112044 KB Output is correct
69 Correct 26 ms 47264 KB Output is correct
70 Correct 23 ms 47208 KB Output is correct
71 Correct 26 ms 47188 KB Output is correct
72 Correct 29 ms 47228 KB Output is correct
73 Correct 22 ms 47188 KB Output is correct
74 Correct 22 ms 47200 KB Output is correct
75 Correct 20 ms 47212 KB Output is correct
76 Correct 23 ms 47272 KB Output is correct
77 Correct 22 ms 47200 KB Output is correct
78 Correct 22 ms 47196 KB Output is correct
79 Correct 22 ms 47188 KB Output is correct
80 Correct 21 ms 47188 KB Output is correct
81 Correct 21 ms 47264 KB Output is correct
82 Correct 21 ms 47236 KB Output is correct
83 Correct 21 ms 47176 KB Output is correct
84 Correct 22 ms 47252 KB Output is correct
85 Correct 21 ms 47220 KB Output is correct
86 Correct 21 ms 47316 KB Output is correct
87 Correct 20 ms 47240 KB Output is correct
88 Correct 21 ms 47308 KB Output is correct
89 Correct 20 ms 47316 KB Output is correct
90 Correct 21 ms 47192 KB Output is correct
91 Correct 21 ms 47188 KB Output is correct
92 Correct 21 ms 47188 KB Output is correct
93 Correct 20 ms 47188 KB Output is correct
94 Correct 23 ms 47288 KB Output is correct
95 Correct 24 ms 47284 KB Output is correct
96 Correct 25 ms 47132 KB Output is correct
97 Correct 24 ms 47232 KB Output is correct
98 Correct 23 ms 47204 KB Output is correct
99 Correct 26 ms 47216 KB Output is correct
100 Correct 234 ms 60960 KB Output is correct
101 Correct 245 ms 61052 KB Output is correct
102 Correct 229 ms 61068 KB Output is correct
103 Correct 253 ms 61012 KB Output is correct
104 Correct 252 ms 61004 KB Output is correct
105 Correct 251 ms 78032 KB Output is correct
106 Correct 290 ms 77960 KB Output is correct
107 Correct 237 ms 77988 KB Output is correct
108 Correct 245 ms 77940 KB Output is correct
109 Correct 232 ms 77904 KB Output is correct
110 Correct 244 ms 60964 KB Output is correct
111 Correct 247 ms 60968 KB Output is correct
112 Correct 222 ms 61048 KB Output is correct
113 Correct 227 ms 61004 KB Output is correct
114 Correct 215 ms 61000 KB Output is correct
115 Correct 258 ms 111888 KB Output is correct
116 Correct 250 ms 111988 KB Output is correct
117 Correct 247 ms 111964 KB Output is correct
118 Correct 261 ms 111948 KB Output is correct
119 Correct 282 ms 112008 KB Output is correct
120 Correct 221 ms 61076 KB Output is correct
121 Correct 230 ms 60988 KB Output is correct
122 Correct 220 ms 60968 KB Output is correct
123 Correct 215 ms 61000 KB Output is correct
124 Correct 231 ms 86424 KB Output is correct
125 Correct 228 ms 86392 KB Output is correct
126 Correct 255 ms 86448 KB Output is correct
127 Correct 219 ms 86400 KB Output is correct
128 Correct 122 ms 54456 KB Output is correct
129 Correct 121 ms 54608 KB Output is correct
130 Correct 121 ms 54456 KB Output is correct
131 Correct 22 ms 47132 KB Output is correct