제출 #1284098

#제출 시각아이디문제언어결과실행 시간메모리
1284098JohanMoney (IZhO17_money)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; bool ok(deque < int > tot, vector < int > cur){ if(cur.back() <= tot[0])return true; if(cur[0] >= tot.back())return true; for(int i = 1; i < tot.size(); i++){ if(cur[0] >= tot[i - 1] && cur.back() <= tot[i]) return true; } return false; } int main(){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; cin >> n; int a[n + 1], idx = 1; deque < int > tot; for(int i = 1; i <= n; i++) cin >> a[i]; tot.push_back(a[1]); for(int i = 2; i <= n; i++){ if(a[i] < a[i - 1])break; tot.push_back(a[i]); idx = i; } int ans = 1; vector < int > cur{a[idx + 1]}; // for(int i = idx + 2; i <= n; i++){ // cout << "tot: "; // for(auto j : tot)cout << j << ' ';cout << endl; // cout << "cur: "; // for(auto j : cur)cout << j << ' ';cout << endl; if(a[i] < a[i - 1]){ multiset < int > st; for(auto j : tot)st.insert(j); for(auto j : cur)st.insert(j); tot.clear(); cur = {a[i]}; for(auto j : st)tot.push_back(j); ans++; continue; } cur.push_back(a[i]); if(ok(tot, cur) == false){ cur.pop_back(); multiset < int > st; for(auto j : tot)st.insert(j); for(auto j : cur)st.insert(j); tot.clear(); cur = {a[i]}; for(auto j : st)tot.push_back(j); ans++; } } cout << ans + 1 << endl; }

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

money.cpp: In function 'int main()':
money.cpp:34:10: error: 'i' was not declared in this scope
   34 |     if(a[i] < a[i - 1]){
      |          ^
money.cpp:39:18: error: no match for 'operator=' (operand types are 'std::vector<int>' and '<brace-enclosed initializer list>')
   39 |       cur = {a[i]};
      |                  ^
In file included from /usr/include/c++/13/vector:72,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from money.cpp:1:
/usr/include/c++/13/bits/vector.tcc:210:5: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/13/vector:66:
/usr/include/c++/13/bits/stl_vector.h:766:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:788:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
money.cpp:42:7: error: continue statement not within a loop
   42 |       continue;
      |       ^~~~~~~~
money.cpp:44:21: error: 'i' was not declared in this scope
   44 |     cur.push_back(a[i]);
      |                     ^
money.cpp:51:18: error: no match for 'operator=' (operand types are 'std::vector<int>' and '<brace-enclosed initializer list>')
   51 |       cur = {a[i]};
      |                  ^
/usr/include/c++/13/bits/vector.tcc:210:5: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:766:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:788:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
money.cpp: At global scope:
money.cpp:56:3: error: 'cout' does not name a type
   56 |   cout << ans + 1 << endl;
      |   ^~~~
money.cpp:57:1: error: expected declaration before '}' token
   57 | }
      | ^