Submission #705556

# Submission time Handle Problem Language Result Execution time Memory
705556 2023-03-04T15:55:18 Z krizsu222 Homework (CEOI22_homework) C++17
0 / 100
119 ms 181060 KB
#include "bits/stdc++.h"
#define TREE_SIZE (1<<20)
#define ls (v * 2)
#define rs (v * 2 + 1)
using namespace std;

struct node
{
    pair <int, int> value;
    string type;
} tree[TREE_SIZE * 2];
string s;

void insert(int v, int mx, int n)
{
    tree[v].value = {1, n};
    while(v != 0)
    {
        v /= 2;
        if(tree[v].type == "max")
        {
            if(rs > mx) tree[v].value = tree[ls].value;
            else tree[v].value = {max(tree[ls].value.first, tree[rs].value.first) + 1, max(tree[ls].value.second, tree[rs].value.second)};
        }
        if(tree[v].type == "min")
        {
            if(rs > mx) tree[v].value = tree[ls].value;
            else tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), min(tree[ls].value.second, tree[rs].value.second) - 1};
        }
    }
}

signed main()
{
    cin.tie(0) -> ios_base::sync_with_stdio(0);
    cin >> s;
    int question_marks = count(s.begin(), s.end(), '?');
    vector <int> q;
    int mx = 0, mm = 0, it = 1, son = 0;
    for(auto u : s)
    {
        if(u == 'm' || u == 'a' || u == 'i') continue;
        if(u == '(') it *= 2;
        if(u == ')') it /= 2;
        it += son;
        int act_son = it;
        if(u == ',') son = 1;
        else son = 0;
        if(u == 'n')
        {
            tree[act_son].type = "min";
            mm++;
        }
        if(u == 'x')
        {
            tree[act_son].type = "max";
            mx++;
        }
        if(u == '?')
        {
            tree[act_son].type = "const";
            q.push_back(act_son);
        }
    }
    //for(auto u : q)
    //    cout << u << ' ';
    for(auto u : q)
        insert(u, q[q.size() - 1], question_marks);
    if(mx == 0 || mm == 0)
        cout << tree[1].value.second - tree[1].value.first << '\n';
    else
        cout << tree[1].value.second - tree[1].value.first + 1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 82380 KB Output is correct
2 Incorrect 36 ms 82324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 82380 KB Output is correct
2 Incorrect 36 ms 82324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 119 ms 181060 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 82380 KB Output is correct
2 Incorrect 36 ms 82324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 82380 KB Output is correct
2 Incorrect 36 ms 82324 KB Output isn't correct
3 Halted 0 ms 0 KB -