Submission #92343

# Submission time Handle Problem Language Result Execution time Memory
92343 2019-01-02T14:26:52 Z Pajaraja Gift (IZhO18_nicegift) C++17
0 / 100
585 ms 45904 KB
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
	if(a==0) return b;
	return gcd(b%a,a);
}
int main()
{
	long long n,k,cnt=0;
	long long t,sum=0,mi=1000000000000000000LL;
	scanf("%lld%lld",&n,&k);
	priority_queue<pair<long long,int> > pq,pq1;
	for(int i=0;i<n;i++) {scanf("%lld",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;}
	if(sum%k!=0) {printf("-1"); return 0;}
	while(pq.size()>=k && mi!=pq.top().first)
	{
		stack<pair<long long,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		long long f=st.top().first;
		if(!pq.empty()) f-=pq.top().first;
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); mi=min(mi,st.top().first); st.pop();}
		cnt++;
	}
	if(pq.size()%n!=0) {printf("-1"); return 0;}
	if(pq.top().first%(k/gcd(n,k))!=0) {printf("-1"); return 0;}
	printf("%lld\n",cnt);
	while(cnt--)
	{
		stack<pair<long long,int> > st;
		for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
		long long f=st.top().first;
		if(!pq1.empty()) f-=pq1.top().first;
		printf("%lld ",f);
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%lld ",st.top().second); st.pop();}
		printf("\n");
	}
	if(pq.top().first%(k/gcd(n,k))!=0) {printf("-1"); return 0;}
	long long f=pq.top().first/(k/gcd(n,k));
	while(pq.size()>=k)
	{
		stack<pair<long long,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		printf("%lld ",f);
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); printf("%d ",st.top().second); st.pop();}
		printf("\n");
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:16:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k && mi!=pq.top().first)
        ~~~~~~~~~^~~
nicegift.cpp:35:116: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%lld ",st.top().second); st.pop();}
                                                                                                     ~~~~~~~~~~~~~~~^
nicegift.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:14:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) {scanf("%lld",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;}
                        ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 585 ms 45904 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -