답안 #48862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48862 2018-05-19T10:50:02 Z mrtsima22 Gift (IZhO18_nicegift) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,k;
long long a[100003],sum,p;
set<pair<long long,int> >s;
vector<vector<int> > ans;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
	cin>>a[i];
	sum=sum+a[i];
}
bool ok=1;
for(int i=2;i<=n;i++)
{
	ok=ok&(a[i]==a[i-1]);
}
if(!(sum<=1000000||ok)){
cout<<-1<<endl;return 0;}
if(sum%k!=0){
cout<<-1<<endl;return 0;}

for(int i=1;i<=n;i++)
{
	s.insert(make_pair(a[i],i));
}
p=1;
if(ok){
	p=sum/(n*(k/__gcd(n,k)));
}
while(s.size())
{
	int t=0;
	vector<int>v;
	while(s.size()&&t<k)
	{
		set<pair<int,int> >::iterator it=s.end();
		it--;
		int u=(*(it)).second;
		s.erase(it);
		v.push_back(u);
		a[u]-=p;
		t++;
	}
	if(t!=k){cout<<-1<<endl;return 0;
	}
	for(int i=0;i<v.size();i++)
	{
		if(a[v[i]]>0)
		{
			s.insert(make_pair(a[v[i]],v[i]));
		}
	}
	ans.push_back(v);
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++)
{
	cout<<p<<" ";
	for(int j=0;j<ans[i].size();j++)
	{
		cout<<ans[i][j]<<" ";
	}
	cout<<endl;
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/


Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:41:41: error: conversion from 'std::set<std::pair<long long int, int> >::iterator {aka std::_Rb_tree_const_iterator<std::pair<long long int, int> >}' to non-scalar type 'std::set<std::pair<int, int> >::iterator {aka std::_Rb_tree_const_iterator<std::pair<int, int> >}' requested
   set<pair<int,int> >::iterator it=s.end();
                                    ~~~~~^~
nicegift.cpp:44:13: error: no matching function for call to 'std::set<std::pair<long long int, int> >::erase(std::set<std::pair<int, int> >::iterator&)'
   s.erase(it);
             ^
In file included from /usr/include/c++/7/set:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:87,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_set.h:644:7: note: candidate: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [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::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >]
       erase(const_iterator __position)
       ^~~~~
/usr/include/c++/7/bits/stl_set.h:644:7: note:   no known conversion for argument 1 from 'std::set<std::pair<int, int> >::iterator {aka std::_Rb_tree_const_iterator<std::pair<int, int> >}' to 'std::set<std::pair<long long int, int> >::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<long long int, int> >}'
/usr/include/c++/7/bits/stl_set.h:674:7: note: candidate: std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_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::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<long long int, int>]
       erase(const key_type& __x)
       ^~~~~
/usr/include/c++/7/bits/stl_set.h:674:7: note:   no known conversion for argument 1 from 'std::set<std::pair<int, int> >::iterator {aka std::_Rb_tree_const_iterator<std::pair<int, int> >}' to 'const key_type& {aka const std::pair<long long int, int>&}'
/usr/include/c++/7/bits/stl_set.h:696:7: note: candidate: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [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::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<long long int, int> >]
       erase(const_iterator __first, const_iterator __last)
       ^~~~~
/usr/include/c++/7/bits/stl_set.h:696:7: note:   candidate expects 2 arguments, 1 provided
nicegift.cpp:51:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++)
              ~^~~~~~~~~
nicegift.cpp:61:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for(int i=0;i<ans.size();i++)
             ~^~~~~~~~~~~
nicegift.cpp:64:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=0;j<ans[i].size();j++)
              ~^~~~~~~~~~~~~~