답안 #76857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76857 2018-09-18T18:10:43 Z zetapi Gift (IZhO18_nicegift) C++14
19 / 100
1313 ms 93028 KB
#include "bits/stdc++.h"
using namespace std;
 
#define pb  push_back
#define mp  make_pair
#define	int long long
#define itr iterator
 
typedef pair<int,int> pii;
 
const int MAX=5e6;
 
set<pii> st;
 
set<pii>::itr it_1,it_2;

vector<int> res;

int N,K,sum,arr[MAX],cnt[MAX];
 
signed main()
{
	ios_base::sync_with_stdio(false);
 
	cin>>N>>K;
	for(int A=1;A<=N;A++)
	{
		cin>>arr[A];
		sum+=arr[A];
		if(arr[A])
			st.insert(mp(-arr[A],A));
	}
	if(sum%K)
		return cout<<-1,0;
	int dif=0,pre=st.begin()->first;
	vector<pii> lol(K);
	while(true)
	{
		if(st.size()<K)
			return cout<<-1,0;
		it_1=st.begin();
		it_2=st.end();
		it_2--;
		if(it_1->first==it_2->first and it_1->first!=pre)
			break;
		dif+=K;
		for(int A=0;A<K;A++)
		{
			lol[A]=*st.begin();
			st.erase(st.begin());
		}
		for(int A=0;A<K;A++)
		{
			lol[A].first++;
			if(lol[A].first!=0)
				st.insert(lol[A]);
			res.pb(lol[A].second);
		}
		/*for(auto A:st)
			cout<<-A.first<<" ";
		cout<<"\n";*/
	}
	cout<<res.size()/K<<"\n";
	for(int A=0;A<res.size();A+=K)
	{
		cout<<sum/dif<<" ";
		for(int B=A;B<A+K;B++)
			cout<<res[B]<<" ";
		cout<<"\n";
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(st.size()<K)
      ~~~~~~~~~^~
nicegift.cpp:64:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=0;A<res.size();A+=K)
              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1313 ms 93028 KB n=1000000
2 Correct 783 ms 93028 KB n=666666
3 Correct 423 ms 93028 KB n=400000
4 Correct 1031 ms 93028 KB n=285714
5 Correct 21 ms 93028 KB n=20000
6 Correct 917 ms 93028 KB n=181818
7 Correct 12 ms 93028 KB n=10000
8 Correct 93 ms 93028 KB n=6666
9 Correct 5 ms 93028 KB n=4000
10 Correct 428 ms 93028 KB n=2857
11 Correct 5 ms 93028 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -