답안 #515939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515939 2022-01-20T07:22:57 Z Joo Lightning Rod (NOI18_lightningrod) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;



int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    stack<pair<int, int>> st;
    
    for(int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        while(!st.empty() and x-st.top().first <= y-st.top().second) st.pop;
        if(st.empty() or (x-st.top().first > y-st.top().second and x-st.top().first > st.top.second-y)) st.push({x, y});
    }

    cout << st.size();

    return 0;
}

Compilation message

lightningrod.cpp: In function 'int main()':
lightningrod.cpp:13:73: error: invalid use of non-static member function 'void std::stack<_Tp, _Sequence>::pop() [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >]'
   13 |         while(!st.empty() and x-st.top().first <= y-st.top().second) st.pop;
      |                                                                      ~~~^~~
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from lightningrod.cpp:1:
/usr/include/c++/10/bits/stl_stack.h:272:7: note: declared here
  272 |       pop()
      |       ^~~
lightningrod.cpp:14:90: error: invalid use of member function 'std::stack<_Tp, _Sequence>::const_reference std::stack<_Tp, _Sequence>::top() const [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::stack<_Tp, _Sequence>::const_reference = const std::pair<int, int>&]' (did you forget the '()' ?)
   14 |         if(st.empty() or (x-st.top().first > y-st.top().second and x-st.top().first > st.top.second-y)) st.push({x, y});
      |                                                                                       ~~~^~~
      |                                                                                             ()
lightningrod.cpp:14:94: error: expected ')' before 'second'
   14 |         if(st.empty() or (x-st.top().first > y-st.top().second and x-st.top().first > st.top.second-y)) st.push({x, y});
      |                          ~                                                                   ^~~~~~
      |                                                                                              )