답안 #734522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734522 2023-05-02T15:01:03 Z danikoynov Homework (CEOI22_homework) C++14
53 / 100
195 ms 67432 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 = 1e6 + 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;
        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 13 ms 23784 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23684 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23672 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23892 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 15 ms 23772 KB Output is correct
12 Correct 14 ms 23716 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23788 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 12 ms 23792 KB Output is correct
18 Correct 11 ms 23708 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 12 ms 23832 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23672 KB Output is correct
24 Correct 15 ms 23724 KB Output is correct
25 Correct 13 ms 23788 KB Output is correct
26 Correct 12 ms 23760 KB Output is correct
27 Correct 12 ms 23784 KB Output is correct
28 Correct 14 ms 23772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23784 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23684 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23672 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23892 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 15 ms 23772 KB Output is correct
12 Correct 14 ms 23716 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23788 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 12 ms 23792 KB Output is correct
18 Correct 11 ms 23708 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 12 ms 23832 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23672 KB Output is correct
24 Correct 15 ms 23724 KB Output is correct
25 Correct 13 ms 23788 KB Output is correct
26 Correct 12 ms 23760 KB Output is correct
27 Correct 12 ms 23784 KB Output is correct
28 Correct 14 ms 23772 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 13 ms 23688 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 13 ms 23764 KB Output is correct
33 Correct 12 ms 23788 KB Output is correct
34 Correct 12 ms 23784 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 13 ms 23696 KB Output is correct
37 Correct 12 ms 23784 KB Output is correct
38 Correct 14 ms 23756 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 16 ms 23788 KB Output is correct
43 Correct 12 ms 23764 KB Output is correct
44 Correct 17 ms 23668 KB Output is correct
45 Correct 13 ms 23776 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 13 ms 23764 KB Output is correct
48 Correct 12 ms 23772 KB Output is correct
49 Correct 12 ms 23788 KB Output is correct
50 Correct 12 ms 23712 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 13 ms 23904 KB Output is correct
53 Correct 12 ms 23744 KB Output is correct
54 Correct 16 ms 23712 KB Output is correct
55 Correct 13 ms 23784 KB Output is correct
56 Correct 12 ms 23676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 195 ms 67432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23784 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23684 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23672 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23892 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 15 ms 23772 KB Output is correct
12 Correct 14 ms 23716 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23788 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 12 ms 23792 KB Output is correct
18 Correct 11 ms 23708 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 12 ms 23832 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23672 KB Output is correct
24 Correct 15 ms 23724 KB Output is correct
25 Correct 13 ms 23788 KB Output is correct
26 Correct 12 ms 23760 KB Output is correct
27 Correct 12 ms 23784 KB Output is correct
28 Correct 14 ms 23772 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 13 ms 23688 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 13 ms 23764 KB Output is correct
33 Correct 12 ms 23788 KB Output is correct
34 Correct 12 ms 23784 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 13 ms 23696 KB Output is correct
37 Correct 12 ms 23784 KB Output is correct
38 Correct 14 ms 23756 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 16 ms 23788 KB Output is correct
43 Correct 12 ms 23764 KB Output is correct
44 Correct 17 ms 23668 KB Output is correct
45 Correct 13 ms 23776 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 13 ms 23764 KB Output is correct
48 Correct 12 ms 23772 KB Output is correct
49 Correct 12 ms 23788 KB Output is correct
50 Correct 12 ms 23712 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 13 ms 23904 KB Output is correct
53 Correct 12 ms 23744 KB Output is correct
54 Correct 16 ms 23712 KB Output is correct
55 Correct 13 ms 23784 KB Output is correct
56 Correct 12 ms 23676 KB Output is correct
57 Correct 12 ms 23764 KB Output is correct
58 Correct 13 ms 23792 KB Output is correct
59 Correct 12 ms 23764 KB Output is correct
60 Correct 12 ms 23748 KB Output is correct
61 Correct 16 ms 23792 KB Output is correct
62 Correct 18 ms 23788 KB Output is correct
63 Correct 14 ms 23764 KB Output is correct
64 Correct 16 ms 23796 KB Output is correct
65 Correct 14 ms 23764 KB Output is correct
66 Correct 14 ms 23764 KB Output is correct
67 Correct 15 ms 23792 KB Output is correct
68 Correct 12 ms 23752 KB Output is correct
69 Correct 12 ms 23788 KB Output is correct
70 Correct 13 ms 23788 KB Output is correct
71 Correct 13 ms 23764 KB Output is correct
72 Correct 15 ms 23764 KB Output is correct
73 Correct 14 ms 23744 KB Output is correct
74 Correct 16 ms 23764 KB Output is correct
75 Correct 15 ms 23788 KB Output is correct
76 Correct 17 ms 23736 KB Output is correct
77 Correct 13 ms 23692 KB Output is correct
78 Correct 12 ms 23764 KB Output is correct
79 Correct 13 ms 23764 KB Output is correct
80 Correct 13 ms 23688 KB Output is correct
81 Correct 12 ms 23764 KB Output is correct
82 Correct 13 ms 23764 KB Output is correct
83 Correct 12 ms 23696 KB Output is correct
84 Correct 15 ms 23764 KB Output is correct
85 Correct 13 ms 23780 KB Output is correct
86 Correct 13 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23784 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23684 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23672 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23892 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 15 ms 23772 KB Output is correct
12 Correct 14 ms 23716 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23788 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 12 ms 23792 KB Output is correct
18 Correct 11 ms 23708 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 12 ms 23832 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23756 KB Output is correct
23 Correct 12 ms 23672 KB Output is correct
24 Correct 15 ms 23724 KB Output is correct
25 Correct 13 ms 23788 KB Output is correct
26 Correct 12 ms 23760 KB Output is correct
27 Correct 12 ms 23784 KB Output is correct
28 Correct 14 ms 23772 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 13 ms 23688 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 13 ms 23764 KB Output is correct
33 Correct 12 ms 23788 KB Output is correct
34 Correct 12 ms 23784 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 13 ms 23696 KB Output is correct
37 Correct 12 ms 23784 KB Output is correct
38 Correct 14 ms 23756 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 16 ms 23788 KB Output is correct
43 Correct 12 ms 23764 KB Output is correct
44 Correct 17 ms 23668 KB Output is correct
45 Correct 13 ms 23776 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 13 ms 23764 KB Output is correct
48 Correct 12 ms 23772 KB Output is correct
49 Correct 12 ms 23788 KB Output is correct
50 Correct 12 ms 23712 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 13 ms 23904 KB Output is correct
53 Correct 12 ms 23744 KB Output is correct
54 Correct 16 ms 23712 KB Output is correct
55 Correct 13 ms 23784 KB Output is correct
56 Correct 12 ms 23676 KB Output is correct
57 Runtime error 195 ms 67432 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -