Submission #48541

# Submission time Handle Problem Language Result Execution time Memory
48541 2018-05-15T14:26:50 Z Pajaraja Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 104984 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;
	scanf("%d%d",&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)); sum+=t;}
	if(sum<=100000)
	{
	while(pq.size()>=k)
	{
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq.push(st.top()); st.pop();}
		cnt++;
	}
	if(!pq.empty()) {printf("-1"); return 0;}
	printf("%d\n",cnt);
	while(pq1.size()>=k)
	{
		stack<pair<int,int> > st;
		printf("1 ");
		for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
		for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
		printf("\n");
	}
	}
	else
	{
	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<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); st.pop();}
		cnt++;
	}
	if(!pq.empty()) {printf("-1"); return 0;}
	printf("%d\n",cnt);
	while(pq1.size()>=k)
	{
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
		printf("%lld ",f);
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
		printf("\n");
	}
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:12:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  scanf("%d%d",&n,&k);
               ~~   ^
nicegift.cpp:12:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
nicegift.cpp:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:25:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n",cnt);
                   ^
nicegift.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq1.size()>=k)
        ~~~~~~~~~~^~~
nicegift.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:47:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n",cnt);
                   ^
nicegift.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq1.size()>=k)
        ~~~~~~~~~~^~~
nicegift.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&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)); sum+=t;}
                        ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 99204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 99204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 99204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2044 ms 104984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 99204 KB Time limit exceeded
2 Halted 0 ms 0 KB -