제출 #1350261

#제출 시각아이디문제언어결과실행 시간메모리
1350261AMel0nHomework (CEOI22_homework)C++20
100 / 100
264 ms175540 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e6 + 5;
const ll INF = 1e18;

vector<vector<ll>> adj;
vector<ll> typ;
unordered_set<ll> leaf;
pair<ll,ll> dfs(ll v) {
    if (typ[v] > 0) {
        auto [mn1, mx1] = dfs(adj[v][0]);
        auto [mn2, mx2] = dfs(adj[v][1]);
        return {mn1 + mn2, min(mx1, mx2)};
    }
    if (typ[v] < 0) {
        auto [mn1, mx1] = dfs(adj[v][0]);
        auto [mn2, mx2] = dfs(adj[v][1]);
        return {min(mn1, mn2), mx1 + mx2};
    }
    if (!typ[v]) return {1, 1};
    // min num of smaller vals required, min num of larger vals required
}
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    string S; cin >> S;
    adj.resize(MAXN);
    typ.resize(MAXN, -INF);
    stack<ll> cur;
    ll i = 0;
    ll cnt = 0;
    while(i < S.size()) {
        if (S[i] == ',') {i++; continue;}
        if (S[i] == ')') {
            cur.pop();
            i++;
            continue;
        }
        if (cur.size()) adj[cur.top()].push_back(cnt);
        if (S[i] == 'm' && S[i+1] == 'i') {
            cur.push(cnt);
            typ[cnt++] = -1;
            i += 4;
            continue;
        }
        if (S[i] == 'm' && S[i+1] == 'a') {
            cur.push(cnt);
            typ[cnt++] = 1;
            i += 4;
            continue;
        }
        if (S[i] == '?') {
            leaf.insert(cnt);
            typ[cnt++] = 0;
            i++;
        }
    }
    auto [l, r] = dfs(0);
    cout << (leaf.size() - r + 1) - l + 1;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'std::pair<long long int, long long int> dfs(ll)':
Main.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
   23 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...