Submission #48542

# Submission time Handle Problem Language Result Execution time Memory
48542 2018-05-15T14:27:48 Z Pajaraja Gift (IZhO18_nicegift) C++17
30 / 100
946 ms 58560 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("%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)); 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("%lld\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("%lld\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:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
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: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("%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)); sum+=t;}
                        ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 476 KB n=3
3 Correct 2 ms 512 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 512 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 476 KB n=3
3 Correct 2 ms 512 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 512 KB n=2
7 Correct 2 ms 512 KB n=5
8 Correct 3 ms 512 KB n=8
9 Correct 12 ms 512 KB n=14
10 Correct 8 ms 512 KB n=11
11 Correct 69 ms 2948 KB n=50000
12 Correct 67 ms 3108 KB n=50000
13 Correct 39 ms 3108 KB n=10
14 Correct 44 ms 3108 KB n=685
15 Correct 51 ms 3108 KB n=623
16 Correct 29 ms 3108 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 476 KB n=3
3 Correct 2 ms 512 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 512 KB n=2
7 Correct 2 ms 512 KB n=5
8 Correct 3 ms 512 KB n=8
9 Correct 12 ms 512 KB n=14
10 Correct 8 ms 512 KB n=11
11 Correct 69 ms 2948 KB n=50000
12 Correct 67 ms 3108 KB n=50000
13 Correct 39 ms 3108 KB n=10
14 Correct 44 ms 3108 KB n=685
15 Correct 51 ms 3108 KB n=623
16 Correct 29 ms 3108 KB n=973
17 Correct 49 ms 3108 KB n=989
18 Correct 23 ms 3108 KB n=563
19 Correct 35 ms 3108 KB n=592
20 Correct 37 ms 3108 KB n=938
21 Correct 28 ms 3108 KB n=747
22 Correct 31 ms 3108 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 946 ms 58560 KB n=1000000
2 Correct 613 ms 58560 KB n=666666
3 Correct 315 ms 58560 KB n=400000
4 Incorrect 445 ms 58560 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 476 KB n=3
3 Correct 2 ms 512 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 512 KB n=2
7 Correct 2 ms 512 KB n=5
8 Correct 3 ms 512 KB n=8
9 Correct 12 ms 512 KB n=14
10 Correct 8 ms 512 KB n=11
11 Correct 69 ms 2948 KB n=50000
12 Correct 67 ms 3108 KB n=50000
13 Correct 39 ms 3108 KB n=10
14 Correct 44 ms 3108 KB n=685
15 Correct 51 ms 3108 KB n=623
16 Correct 29 ms 3108 KB n=973
17 Correct 49 ms 3108 KB n=989
18 Correct 23 ms 3108 KB n=563
19 Correct 35 ms 3108 KB n=592
20 Correct 37 ms 3108 KB n=938
21 Correct 28 ms 3108 KB n=747
22 Correct 31 ms 3108 KB n=991
23 Correct 946 ms 58560 KB n=1000000
24 Correct 613 ms 58560 KB n=666666
25 Correct 315 ms 58560 KB n=400000
26 Incorrect 445 ms 58560 KB Jury has the answer but participant has not
27 Halted 0 ms 0 KB -