답안 #170897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170897 2019-12-26T16:42:06 Z emil_physmath Gift (IZhO18_nicegift) C++17
컴파일 오류
0 ms 0 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
const int maxN = 100001;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<llong> arr(n);
    multiset<pair<llong, int>> a;
    llong mx = -1, sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        for (; cur.size() < k; ++it)
        {
            cur.push_back(it->second);
            mn = min(mn, it->first);
        }
        if (it != a.rend())
            mn = min(mn, max(sum / k - it->first - 1, 1));
        if (!mn) throw;
        // it->first <= (sum - k * mn) / k
        // k * it->first <= sum - k * mn
        // mn * k <= sum - k * it->first
        // mn <= sum / k - it->first
        /*
            mn = min(mn, a.rbegin()->first - it->first + 1);
        */
        /*
        if (!mn)
        {
            cout << -1 << endl;
            exit(0);
        }
        */
        for (int x: cur)
        {
            a.erase({arr[x], x});
            a.insert({arr[x] -= mn, x});
        }
        ans.push_back({mn, cur});
        /*cerr << "a` ";
        for (pair<llong, int> i: a)
            cerr << i.first << ' ';
        cerr << endl;*/
    }
    cout << ans.size() << '\n';
    for (auto x: ans)
    {
        cout << x.first << ' ';
        for (int y: x.second)
            cout << y + 1 << ' ';
        cout << '\n';
    }
}
// 6 5 4 3 x
// x x-1 x-2 x-3 x

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:26:16: error: 'cur' was not declared in this scope
         for (; cur.size() < k; ++it)
                ^~~
nicegift.cpp:26:34: error: 'it' was not declared in this scope
         for (; cur.size() < k; ++it)
                                  ^~
nicegift.cpp:26:34: note: suggested alternative: 'i'
         for (; cur.size() < k; ++it)
                                  ^~
                                  i
nicegift.cpp:29:13: error: 'mn' was not declared in this scope
             mn = min(mn, it->first);
             ^~
nicegift.cpp:29:13: note: suggested alternative: 'mx'
             mn = min(mn, it->first);
             ^~
             mx
nicegift.cpp:31:13: error: 'it' was not declared in this scope
         if (it != a.rend())
             ^~
nicegift.cpp:31:13: note: suggested alternative: 'i'
         if (it != a.rend())
             ^~
             i
nicegift.cpp:32:13: error: 'mn' was not declared in this scope
             mn = min(mn, max(sum / k - it->first - 1, 1));
             ^~
nicegift.cpp:32:13: note: suggested alternative: 'mx'
             mn = min(mn, max(sum / k - it->first - 1, 1));
             ^~
             mx
nicegift.cpp:33:14: error: 'mn' was not declared in this scope
         if (!mn) throw;
              ^~
nicegift.cpp:33:14: note: suggested alternative: 'mx'
         if (!mn) throw;
              ^~
              mx
nicegift.cpp:48:21: error: 'cur' was not declared in this scope
         for (int x: cur)
                     ^~~
nicegift.cpp:51:33: error: 'mn' was not declared in this scope
             a.insert({arr[x] -= mn, x});
                                 ^~
nicegift.cpp:51:33: note: suggested alternative: 'mx'
             a.insert({arr[x] -= mn, x});
                                 ^~
                                 mx
nicegift.cpp:51:39: error: no matching function for call to 'std::multiset<std::pair<long long int, int> >::insert(<brace-enclosed initializer list>)'
             a.insert({arr[x] -= mn, x});
                                       ^
In file included from /usr/include/c++/7/set:62:0,
                 from nicegift.cpp:7:
/usr/include/c++/7/bits/stl_multiset.h:492:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<long long int, int>]
       insert(const value_type& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:492:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<long long int, int>&}'
/usr/include/c++/7/bits/stl_multiset.h:497:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<long long int, int>]
       insert(value_type&& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:497:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<std::pair<long long int, int> >::value_type&& {aka std::pair<long long int, int>&&}'
/usr/include/c++/7/bits/stl_multiset.h:522:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<long long int, int>]
       insert(const_iterator __position, const value_type& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:522:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/7/bits/stl_multiset.h:527:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::value_type = std::pair<long long int, int>]
       insert(const_iterator __position, value_type&& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:527:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/7/bits/stl_multiset.h:541:2: note: candidate: template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]
  insert(_InputIterator __first, _InputIterator __last)
  ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:541:2: note:   template argument deduction/substitution failed:
nicegift.cpp:51:39: note:   candidate expects 2 arguments, 1 provided
             a.insert({arr[x] -= mn, x});
                                       ^
In file included from /usr/include/c++/7/set:62:0,
                 from nicegift.cpp:7:
/usr/include/c++/7/bits/stl_multiset.h:553:7: note: candidate: void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >]
       insert(initializer_list<value_type> __l)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:553:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::pair<long long int, int> >'
/usr/include/c++/7/bits/stl_multiset.h:573:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::node_type&&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::node_type = std::_Node_handle<std::pair<long long int, int>, std::pair<long long int, int>, std::allocator<std::_Rb_tree_node<std::pair<long long int, int> > > >]
       insert(node_type&& __nh)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:573:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<std::pair<long long int, int> >::node_type&& {aka std::_Node_handle<std::pair<long long int, int>, std::pair<long long int, int>, std::allocator<std::_Rb_tree_node<std::pair<long long int, int> > > >&&}'
/usr/include/c++/7/bits/stl_multiset.h:578:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::node_type&&) [with _Key = std::pair<long long int, int>; _Compare = std::less<std::pair<long long int, int> >; _Alloc = std::allocator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::multiset<_Key, _Compare, _Alloc>::node_type = std::_Node_handle<std::pair<long long int, int>, std::pair<long long int, int>, std::allocator<std::_Rb_tree_node<std::pair<long long int, int> > > >]
       insert(const_iterator __hint, node_type&& __nh)
       ^~~~~~
/usr/include/c++/7/bits/stl_multiset.h:578:7: note:   candidate expects 2 arguments, 1 provided
nicegift.cpp:53:9: error: 'ans' was not declared in this scope
         ans.push_back({mn, cur});
         ^~~
nicegift.cpp:53:9: note: suggested alternative: 'abs'
         ans.push_back({mn, cur});
         ^~~
         abs
nicegift.cpp:53:24: error: 'mn' was not declared in this scope
         ans.push_back({mn, cur});
                        ^~
nicegift.cpp:53:24: note: suggested alternative: 'mx'
         ans.push_back({mn, cur});
                        ^~
                        mx
nicegift.cpp:53:28: error: 'cur' was not declared in this scope
         ans.push_back({mn, cur});
                            ^~~
nicegift.cpp:59:13: error: 'ans' was not declared in this scope
     cout << ans.size() << '\n';
             ^~~
nicegift.cpp:59:13: note: suggested alternative: 'abs'
     cout << ans.size() << '\n';
             ^~~
             abs
nicegift.cpp:60:18: error: unable to deduce 'auto&&' from 'ans'
     for (auto x: ans)
                  ^~~
nicegift.cpp:22:11: warning: unused variable 'mx' [-Wunused-variable]
     llong mx = -1, sum = 0;
           ^~