제출 #1309904

#제출 시각아이디문제언어결과실행 시간메모리
1309904buzdiSails (IOI07_sails)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define int long long using namespace std; const int NMAX = 1e5 + 10; ll answer; int n; int h[NMAX + 1], k[NMAX + 1]; set<pair<int, int>> s; int mars[NMAX + 5]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> h[i] >> k[i]; } for(int i = 1; i <= n; i++) { s.insert(make_pair(h[i], i)); } while(!s.empty()) { auto it = prev(s.end()); auto [curent_h, pos] = *it; int next_h = max(curent_h - k[pos] + 1, 1LL); mars[next_h]++; mars[curent_h + 1]--; k[pos] -= curent_h - next_h + 1; curent_h = next_h - 1; if(!k[pos]) { s.erase(it); } while(!s.empty() && curent_h > 0) { auto it = s.lower_bound(make_pair(curent_h, 0LL)); if(it == s.end()) { break; } int pos = it->second; int next_h = max(curent_h - k[pos] + 1, 1); mars[next_h]++; mars[curent_h + 1]--; k[pos] -= curent_h - next_h + 1; curent_h = next_h - 1; if(!k[pos]) { s.erase(it); } } } for(int i = 1; i <= NMAX; i++) { mars[i] += mars[i - 1]; } for(int i = 1; i <= NMAX; i++) { answer += (ll) mars[i] * (mars[i] - 1) / 2; } cout << answer << '\n'; return 0; }

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

sails.cpp: In function 'int main()':
sails.cpp:51:29: error: no matching function for call to 'max(std::tuple_element<0, std::pair<long long int, long long int> >::type, int)'
   51 |             int next_h = max(curent_h - k[pos] + 1, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from sails.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
sails.cpp:51:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |             int next_h = max(curent_h - k[pos] + 1, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
sails.cpp:51:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |             int next_h = max(curent_h - k[pos] + 1, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
sails.cpp:51:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |             int next_h = max(curent_h - k[pos] + 1, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
sails.cpp:51:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |             int next_h = max(curent_h - k[pos] + 1, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~