Submission #291477

# Submission time Handle Problem Language Result Execution time Memory
291477 2020-09-05T11:15:11 Z Pyqe Gift (IZhO18_nicegift) C++14
19 / 100
687 ms 125864 KB
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

long long n,d,ttl=0,nn=0,a[2000069],cra[2069],wg[2000069],zs=0,inf=1e18;
pair<long long,pair<long long,long long>> as[4000069];
vector<long long> sq[2000069];

int main()
{
	long long i,j,k,l,w,y=1,x=0,mx=-inf;
	
	scanf("%lld%lld",&n,&d);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
		ttl+=a[i];
		mx=max(mx,a[i]);
	}
	if(ttl%d||mx>ttl/d)
	{
		printf("-1\n");
	}
	for(i=1;i<=n;i++)
	{
		nn++;
		as[nn]={x,{y,i}};
		x+=a[i];
		if(x>=ttl/d)
		{
			y++;
			x-=ttl/d;
			if(x)
			{
				nn++;
				as[nn]={0,{y,i}};
			}
		}
	}
	sort(as+1,as+nn+1);
	as[nn+1].fr=ttl/d;
	for(i=1;i<=nn;i++)
	{
		k=as[i].fr;
		l=as[i].sc.fr;
		w=as[i].sc.sc;
		cra[l]=w;
		if(k!=as[i+1].fr)
		{
			zs++;
			wg[zs]=as[i+1].fr-k;
			for(j=1;j<=d;j++)
			{
				sq[zs].push_back(cra[j]);
			}
		}
	}
	printf("%lld\n",zs);
	for(i=1;i<=zs;i++)
	{
		printf("%lld ",wg[i]);
		for(j=0;j<d;j++)
		{
			printf("%lld%c",sq[i][j]," \n"[j==d-1]);
		}
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%lld%lld",&n,&d);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%lld",a+i);
      |   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47352 KB n=4
2 Correct 29 ms 47352 KB n=3
3 Incorrect 30 ms 47360 KB Extra information in the output file
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47352 KB n=4
2 Correct 29 ms 47352 KB n=3
3 Incorrect 30 ms 47360 KB Extra information in the output file
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47352 KB n=4
2 Correct 29 ms 47352 KB n=3
3 Incorrect 30 ms 47360 KB Extra information in the output file
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 687 ms 125864 KB n=1000000
2 Correct 375 ms 97272 KB n=666666
3 Correct 225 ms 76024 KB n=400000
4 Correct 489 ms 101752 KB n=285714
5 Correct 41 ms 48504 KB n=20000
6 Correct 461 ms 97784 KB n=181818
7 Correct 34 ms 47992 KB n=10000
8 Correct 80 ms 53752 KB n=6666
9 Correct 32 ms 47616 KB n=4000
10 Correct 328 ms 79864 KB n=2857
11 Correct 31 ms 47480 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 29 ms 47352 KB n=4
2 Correct 29 ms 47352 KB n=3
3 Incorrect 30 ms 47360 KB Extra information in the output file
4 Halted 0 ms 0 KB -