답안 #861229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861229 2023-10-15T16:58:06 Z vgtcross Homework (CEOI22_homework) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = int(1e6) + 1000;

vector<int> ch[N];
vector<int> d[N];
int l[N], r[N];
int x[N];

void solve() {
    string s;
    cin >> s;
    
    vector<pii> st;
    st.push_back({0, 0});
    
    int w = 1;
    int i = 0;
    while (i < s.size()) {
        if (s[i] == '?') {
            ch[st.back().first].push_back(w);
            d[st.back().second+1].push_back(w++);
        } else if (s[i] == 'm') {
            x[w] = s[i+1] == 'a' ? 2 : 1;
            ch[st.back().first].push_back(w);
            d[st.back().second+1].push_back(w);
            st.push_back({w++, st.top().second+1});
            i += 3;
        } else if (s[i] == ')') st.pop_back();
        ++i;
    }
    
    for (int i = 1e6; i > 0; --i) {
        for (int u : d[i]) {
            if (x[u] == 0) {
                l[u] = r[u] = 0;
            } else if (x[u] == 1) {
                l[u] = min(l[ch[u][0]], l[ch[u][1]]);
                r[u] = r[ch[u][0]] + r[ch[u][1]] + 1;
            } else {
                l[u] = l[ch[u][0]] + l[ch[u][1]] + 1;
                r[u] = min(r[ch[u][0]], r[ch[u][1]]);
            }
        }
    }
    
    int cnt = 0;
    for (char c : s) cnt += c == '?';
    cout << cnt - l[1] - r[1] << '\n';
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (i < s.size()) {
      |            ~~^~~~~~~~~~
Main.cpp:31:35: error: 'class std::vector<std::pair<int, int> >' has no member named 'top'
   31 |             st.push_back({w++, st.top().second+1});
      |                                   ^~~
Main.cpp:31:50: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   31 |             st.push_back({w++, st.top().second+1});
      |                                                  ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~