답안 #734519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734519 2023-05-02T14:55:34 Z danikoynov Homework (CEOI22_homework) C++14
53 / 100
190 ms 67448 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
    {

        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;
                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 11 ms 23764 KB Output is correct
2 Correct 12 ms 23692 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23668 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23684 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 14 ms 23680 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 11 ms 23748 KB Output is correct
14 Correct 12 ms 23724 KB Output is correct
15 Correct 12 ms 23760 KB Output is correct
16 Correct 12 ms 23776 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23692 KB Output is correct
19 Correct 13 ms 23760 KB Output is correct
20 Correct 11 ms 23728 KB Output is correct
21 Correct 11 ms 23668 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 13 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 12 ms 23724 KB Output is correct
28 Correct 14 ms 23784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23692 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23668 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23684 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 14 ms 23680 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 11 ms 23748 KB Output is correct
14 Correct 12 ms 23724 KB Output is correct
15 Correct 12 ms 23760 KB Output is correct
16 Correct 12 ms 23776 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23692 KB Output is correct
19 Correct 13 ms 23760 KB Output is correct
20 Correct 11 ms 23728 KB Output is correct
21 Correct 11 ms 23668 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 13 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 12 ms 23724 KB Output is correct
28 Correct 14 ms 23784 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 11 ms 23764 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 11 ms 23708 KB Output is correct
34 Correct 11 ms 23764 KB Output is correct
35 Correct 14 ms 23728 KB Output is correct
36 Correct 12 ms 23712 KB Output is correct
37 Correct 13 ms 23764 KB Output is correct
38 Correct 11 ms 23764 KB Output is correct
39 Correct 11 ms 23712 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 11 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 12 ms 23784 KB Output is correct
44 Correct 11 ms 23672 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 11 ms 23764 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23744 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23776 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 13 ms 23764 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 190 ms 67448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23692 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23668 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23684 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 14 ms 23680 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 11 ms 23748 KB Output is correct
14 Correct 12 ms 23724 KB Output is correct
15 Correct 12 ms 23760 KB Output is correct
16 Correct 12 ms 23776 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23692 KB Output is correct
19 Correct 13 ms 23760 KB Output is correct
20 Correct 11 ms 23728 KB Output is correct
21 Correct 11 ms 23668 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 13 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 12 ms 23724 KB Output is correct
28 Correct 14 ms 23784 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 11 ms 23764 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 11 ms 23708 KB Output is correct
34 Correct 11 ms 23764 KB Output is correct
35 Correct 14 ms 23728 KB Output is correct
36 Correct 12 ms 23712 KB Output is correct
37 Correct 13 ms 23764 KB Output is correct
38 Correct 11 ms 23764 KB Output is correct
39 Correct 11 ms 23712 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 11 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 12 ms 23784 KB Output is correct
44 Correct 11 ms 23672 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 11 ms 23764 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23744 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23776 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 13 ms 23764 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23764 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 11 ms 23716 KB Output is correct
59 Correct 11 ms 23692 KB Output is correct
60 Correct 13 ms 23776 KB Output is correct
61 Correct 12 ms 23724 KB Output is correct
62 Correct 11 ms 23768 KB Output is correct
63 Correct 14 ms 23816 KB Output is correct
64 Correct 14 ms 23740 KB Output is correct
65 Correct 12 ms 23892 KB Output is correct
66 Correct 12 ms 23736 KB Output is correct
67 Correct 11 ms 23764 KB Output is correct
68 Correct 11 ms 23796 KB Output is correct
69 Correct 11 ms 23764 KB Output is correct
70 Correct 11 ms 23764 KB Output is correct
71 Correct 12 ms 23764 KB Output is correct
72 Correct 12 ms 23760 KB Output is correct
73 Correct 12 ms 23764 KB Output is correct
74 Correct 11 ms 23764 KB Output is correct
75 Correct 13 ms 23844 KB Output is correct
76 Correct 12 ms 23764 KB Output is correct
77 Correct 14 ms 23724 KB Output is correct
78 Correct 11 ms 23764 KB Output is correct
79 Correct 11 ms 23764 KB Output is correct
80 Correct 12 ms 23760 KB Output is correct
81 Correct 13 ms 23820 KB Output is correct
82 Correct 12 ms 23804 KB Output is correct
83 Correct 11 ms 23764 KB Output is correct
84 Correct 11 ms 23676 KB Output is correct
85 Correct 11 ms 23764 KB Output is correct
86 Correct 12 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23692 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Correct 11 ms 23668 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23684 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 14 ms 23680 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 11 ms 23748 KB Output is correct
14 Correct 12 ms 23724 KB Output is correct
15 Correct 12 ms 23760 KB Output is correct
16 Correct 12 ms 23776 KB Output is correct
17 Correct 12 ms 23784 KB Output is correct
18 Correct 13 ms 23692 KB Output is correct
19 Correct 13 ms 23760 KB Output is correct
20 Correct 11 ms 23728 KB Output is correct
21 Correct 11 ms 23668 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 13 ms 23764 KB Output is correct
24 Correct 13 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 12 ms 23724 KB Output is correct
28 Correct 14 ms 23784 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 11 ms 23764 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 11 ms 23708 KB Output is correct
34 Correct 11 ms 23764 KB Output is correct
35 Correct 14 ms 23728 KB Output is correct
36 Correct 12 ms 23712 KB Output is correct
37 Correct 13 ms 23764 KB Output is correct
38 Correct 11 ms 23764 KB Output is correct
39 Correct 11 ms 23712 KB Output is correct
40 Correct 11 ms 23764 KB Output is correct
41 Correct 11 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 12 ms 23784 KB Output is correct
44 Correct 11 ms 23672 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 11 ms 23764 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23744 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23776 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 13 ms 23764 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23764 KB Output is correct
57 Runtime error 190 ms 67448 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -