Submission #291478

# Submission time Handle Problem Language Result Execution time Memory
291478 2020-09-05T11:17:03 Z Pyqe Gift (IZhO18_nicegift) C++14
100 / 100
965 ms 155896 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");
		return 0;
	}
	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 30 ms 47360 KB n=4
2 Correct 29 ms 47360 KB n=3
3 Correct 29 ms 47232 KB n=3
4 Correct 30 ms 47360 KB n=4
5 Correct 31 ms 47232 KB n=4
6 Correct 29 ms 47232 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB n=4
2 Correct 29 ms 47360 KB n=3
3 Correct 29 ms 47232 KB n=3
4 Correct 30 ms 47360 KB n=4
5 Correct 31 ms 47232 KB n=4
6 Correct 29 ms 47232 KB n=2
7 Correct 31 ms 47352 KB n=5
8 Correct 31 ms 47360 KB n=8
9 Correct 30 ms 47360 KB n=14
10 Correct 29 ms 47352 KB n=11
11 Correct 58 ms 51320 KB n=50000
12 Correct 62 ms 51064 KB n=50000
13 Correct 30 ms 47352 KB n=10
14 Correct 30 ms 47360 KB n=685
15 Correct 30 ms 47352 KB n=623
16 Correct 30 ms 47352 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB n=4
2 Correct 29 ms 47360 KB n=3
3 Correct 29 ms 47232 KB n=3
4 Correct 30 ms 47360 KB n=4
5 Correct 31 ms 47232 KB n=4
6 Correct 29 ms 47232 KB n=2
7 Correct 31 ms 47352 KB n=5
8 Correct 31 ms 47360 KB n=8
9 Correct 30 ms 47360 KB n=14
10 Correct 29 ms 47352 KB n=11
11 Correct 58 ms 51320 KB n=50000
12 Correct 62 ms 51064 KB n=50000
13 Correct 30 ms 47352 KB n=10
14 Correct 30 ms 47360 KB n=685
15 Correct 30 ms 47352 KB n=623
16 Correct 30 ms 47352 KB n=973
17 Correct 31 ms 47352 KB n=989
18 Correct 34 ms 47388 KB n=563
19 Correct 32 ms 47532 KB n=592
20 Correct 33 ms 47480 KB n=938
21 Correct 31 ms 47432 KB n=747
22 Correct 32 ms 47488 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 666 ms 112248 KB n=1000000
2 Correct 362 ms 88056 KB n=666666
3 Correct 223 ms 70520 KB n=400000
4 Correct 481 ms 97928 KB n=285714
5 Correct 39 ms 48248 KB n=20000
6 Correct 434 ms 95356 KB n=181818
7 Correct 35 ms 47744 KB n=10000
8 Correct 82 ms 53752 KB n=6666
9 Correct 32 ms 47488 KB n=4000
10 Correct 321 ms 79748 KB n=2857
11 Correct 31 ms 47488 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47360 KB n=4
2 Correct 29 ms 47360 KB n=3
3 Correct 29 ms 47232 KB n=3
4 Correct 30 ms 47360 KB n=4
5 Correct 31 ms 47232 KB n=4
6 Correct 29 ms 47232 KB n=2
7 Correct 31 ms 47352 KB n=5
8 Correct 31 ms 47360 KB n=8
9 Correct 30 ms 47360 KB n=14
10 Correct 29 ms 47352 KB n=11
11 Correct 58 ms 51320 KB n=50000
12 Correct 62 ms 51064 KB n=50000
13 Correct 30 ms 47352 KB n=10
14 Correct 30 ms 47360 KB n=685
15 Correct 30 ms 47352 KB n=623
16 Correct 30 ms 47352 KB n=973
17 Correct 31 ms 47352 KB n=989
18 Correct 34 ms 47388 KB n=563
19 Correct 32 ms 47532 KB n=592
20 Correct 33 ms 47480 KB n=938
21 Correct 31 ms 47432 KB n=747
22 Correct 32 ms 47488 KB n=991
23 Correct 666 ms 112248 KB n=1000000
24 Correct 362 ms 88056 KB n=666666
25 Correct 223 ms 70520 KB n=400000
26 Correct 481 ms 97928 KB n=285714
27 Correct 39 ms 48248 KB n=20000
28 Correct 434 ms 95356 KB n=181818
29 Correct 35 ms 47744 KB n=10000
30 Correct 82 ms 53752 KB n=6666
31 Correct 32 ms 47488 KB n=4000
32 Correct 321 ms 79748 KB n=2857
33 Correct 31 ms 47488 KB n=2000
34 Correct 48 ms 49532 KB n=23514
35 Correct 49 ms 49528 KB n=23514
36 Correct 30 ms 47352 KB n=940
37 Correct 30 ms 47360 KB n=2
38 Correct 144 ms 62456 KB n=100000
39 Correct 168 ms 62568 KB n=100000
40 Correct 30 ms 47360 KB n=10
41 Correct 30 ms 47360 KB n=100
42 Correct 37 ms 48120 KB n=1000
43 Correct 762 ms 145272 KB n=1000000
44 Correct 965 ms 155896 KB n=1000000
45 Correct 683 ms 134648 KB n=666666
46 Correct 605 ms 117176 KB n=400000
47 Correct 310 ms 75256 KB n=2336
48 Correct 494 ms 101972 KB n=285714
49 Correct 454 ms 97904 KB n=181818
50 Correct 345 ms 81912 KB n=40000
51 Correct 331 ms 79736 KB n=20000
52 Correct 322 ms 77944 KB n=10000
53 Correct 329 ms 84472 KB n=6666
54 Correct 335 ms 73080 KB n=4000
55 Correct 331 ms 79864 KB n=2857
56 Correct 308 ms 71928 KB n=2000