이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<iomanip>
#include<algorithm>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<deque>
#include<math.h>
#include<assert.h>
#include<string.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
const int64_t INF = (int64_t) 1e18 + 100;
const int64_t mINF = (int64_t) 1e9 + 100;
const int64_t MOD = 1e9 + 19972207;
const int64_t MOD2 = 998244353;
const int nbit = 31;
const int ndig = 10;
const int nchar = 26;
const int D = 4;
int dr[D] = {-1, 0, 1, 0};
int dc[D] = {0, 1, 0, -1};
const int Dk = 8;
int drk[Dk] = {2, 2, -2, -2, 1, 1, -1, -1};
int dck[Dk] = {1, -1, 1, -1, 2, -2, 2, -2};
struct Query
{
    int t;
    int k;
    int id;
    Query(int t_, int k_, int id_) : t(t_), k(k_), id(id_) {}
    bool operator < (const Query& o) const
    {
        if(t != o.t) return t < o.t;
        if(k != o.k) return k < o.k;
        return id < o.id;
    }
};
struct Thing
{
    int val;
    int l;
    int r;
    Thing(int val_, int l_, int r_) : val(val_), l(l_), r(r_) {}
    bool operator < (const Thing& o) const
    {
        if(val == o.val)
        {
            if(l == o.l) return r < o.r;
            return l < o.l;
        }
        return val < o.val;
    }
};
struct Solution
{
    int n;
    int k;
    string tmp;
    vector<int> b;
    vector<string> s;
    vector<int> l;
    vector<int> r;
    vector<int> cnt;
    vector<pair<int, int> > range;
    Solution() {}
    void solve()
    {
        cin >> tmp;
        n = tmp.length();
        int id = 0;
        while(id < n)
        {
            string t;
            if('a' <= tmp[id] && tmp[id] <= 'z')
            {
                while(id < n && 'a' <= tmp[id] && tmp[id] <= 'z') t.push_back(tmp[id++]);
            }
            else if(tmp[id] == '?') t.push_back(tmp[id++]);
            else if(tmp[id] == ')') t.push_back(tmp[id++]);
            else id++;
            if((int) t.length() != 0) s.push_back(t);
        }
        stack<int> st;
        n = 0;
        for(int i = 0; i < (int) s.size(); i++)
        {
            if(s[i] != ")")
            {
                l.push_back(-1);
                r.push_back(-1);
                cnt.push_back(1);
                st.push(n++);
                if(s[i] == "min") b.push_back(-1);
                if(s[i] == "max") b.push_back(1);
                if(s[i] == "?") b.push_back(0);
            }
            else
            {
                int y = st.top();
                st.pop();
                int x = st.top();
                st.pop();
                l[st.top()] = x;
                r[st.top()] = y;
            }
        }
        range.resize(n, make_pair(1, 1));
        int x = st.top();
        DFS(x);
        cout << range[x].second - range[x].first + 1 << "\n";
    }
    void DFS(int u)
    {
        if(l[u] != -1) DFS(l[u]);
        if(r[u] != -1) DFS(r[u]);
        if(b[u] == 0) return;
        cnt[u] = cnt[l[u]] + cnt[r[u]];
        if(b[u] == 1) range[u] = make_pair(range[l[u]].first + range[r[u]].first,
                                           max(cnt[r[u]] + range[l[u]].second, cnt[l[u]] + range[r[u]].second));
        if(b[u] == -1) range[u] = make_pair(min(range[l[u]].first, range[r[u]].first),
                                            range[l[u]].second + range[r[u]].second - 1);
    }
    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;
        return res;
    }
    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;
        return res;
    }
    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return res % MOD;
    }
    int Abs(int t1)
    {
        if(t1 < 0) return -t1;
        return t1;
    }
    int MASK(int j)
    {
        return (1 << j);
    }
    bool BIT(int t1, int j)
    {
        return (t1 & MASK(j));
    }
};
void __setup()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}
int main()
{
    __setup();
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |