답안 #705559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705559 2023-03-04T16:03:09 Z krizsu222 Homework (CEOI22_homework) C++17
0 / 100
235 ms 524288 KB
#include "bits/stdc++.h"
#define TREE_SIZE (1<<23)
#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")
        {
            tree[v].value = {tree[ls].value.first + tree[rs].value.first, max(tree[ls].value.second, tree[rs].value.second)};
        }
        if(tree[v].type == "min")
        {
            tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), tree[ls].value.second + tree[rs].value.second - n - 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)
        insert(u, q[q.size() - 1], question_marks);
    cout << tree[1].value.second - tree[1].value.first + 1 << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 208 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -