답안 #385603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385603 2021-04-04T15:52:51 Z patrikpavic2 Gift (IZhO18_nicegift) C++17
100 / 100
1253 ms 94620 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>

#define X first
#define Y second
#define PB push_back

using namespace std;

const int N = 2e6 + 500;

typedef long long ll;

int n, k; 
ll sm, A[N];
vector < pair < ll, int >  > swp;
vector < ll > kv;

int main(){	
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++){
		scanf("%lld", A + i);
		sm += A[i];
	}
	if(sm % k != 0){
		printf("-1\n");
		return 0;
	}
	ll cik = (ll)sm / k;
	for(int i = 1;i <= n;i++){
		if(A[i] > cik){
			printf("-1\n");
			return 0;
		}
	}
	ll cur = 0;
	for(int i = 1;i <= n;i++){
		if(cur + A[i] <= cik){
			if(cur + A[i] < cik) 
				swp.PB({cur + A[i], -i});
			swp.PB({cur, i}); kv.PB(cur);
			cur = (cur + A[i]) % cik;
		}
		else{
			swp.PB({cur, i}); kv.PB(cur);
			swp.PB({0, i}); kv.PB(0);
			swp.PB({A[i] - (cik - cur), -i});
			cur = A[i] - (cik - cur);
		}
	}
	sort(kv.begin(), kv.end());
	kv.erase(unique(kv.begin(), kv.end()), kv.end());
	printf("%d\n", (int)kv.size());
	set < int > S;
	sort(swp.begin(), swp.end());
	for(int i = 0;i < (int)swp.size();){
		int j = i;
		while(i < (int)swp.size() && swp[i].X == swp[j].X){
			if(swp[i].Y > 0) S.insert(swp[i].Y);
			else 		     S.erase(-swp[i].Y);
			i++;
		}
		ll len = (i == (int)swp.size() ? cik : swp[i].X) - swp[j].X;
		printf("%lld ", len);
		for(int x : S)
			printf("%d ", x);
		printf("\n");
	}
	return 0;
}




Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   scanf("%lld", A + i);
      |   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 38 ms 3932 KB n=50000
12 Correct 44 ms 3804 KB n=50000
13 Correct 2 ms 364 KB n=10
14 Correct 2 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 38 ms 3932 KB n=50000
12 Correct 44 ms 3804 KB n=50000
13 Correct 2 ms 364 KB n=10
14 Correct 2 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
17 Correct 2 ms 364 KB n=989
18 Correct 2 ms 364 KB n=563
19 Correct 3 ms 364 KB n=592
20 Correct 3 ms 492 KB n=938
21 Correct 3 ms 364 KB n=747
22 Correct 4 ms 492 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 918 ms 73056 KB n=1000000
2 Correct 443 ms 54708 KB n=666666
3 Correct 320 ms 32564 KB n=400000
4 Correct 543 ms 39092 KB n=285714
5 Correct 15 ms 2148 KB n=20000
6 Correct 387 ms 29000 KB n=181818
7 Correct 8 ms 1256 KB n=10000
8 Correct 56 ms 2408 KB n=6666
9 Correct 7 ms 620 KB n=4000
10 Correct 242 ms 9964 KB n=2857
11 Correct 2 ms 492 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 38 ms 3932 KB n=50000
12 Correct 44 ms 3804 KB n=50000
13 Correct 2 ms 364 KB n=10
14 Correct 2 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
17 Correct 2 ms 364 KB n=989
18 Correct 2 ms 364 KB n=563
19 Correct 3 ms 364 KB n=592
20 Correct 3 ms 492 KB n=938
21 Correct 3 ms 364 KB n=747
22 Correct 4 ms 492 KB n=991
23 Correct 918 ms 73056 KB n=1000000
24 Correct 443 ms 54708 KB n=666666
25 Correct 320 ms 32564 KB n=400000
26 Correct 543 ms 39092 KB n=285714
27 Correct 15 ms 2148 KB n=20000
28 Correct 387 ms 29000 KB n=181818
29 Correct 8 ms 1256 KB n=10000
30 Correct 56 ms 2408 KB n=6666
31 Correct 7 ms 620 KB n=4000
32 Correct 242 ms 9964 KB n=2857
33 Correct 2 ms 492 KB n=2000
34 Correct 37 ms 2272 KB n=23514
35 Correct 24 ms 2272 KB n=23514
36 Correct 2 ms 364 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 146 ms 9812 KB n=100000
39 Correct 119 ms 9684 KB n=100000
40 Correct 2 ms 364 KB n=10
41 Correct 2 ms 364 KB n=100
42 Correct 8 ms 620 KB n=1000
43 Correct 831 ms 83900 KB n=1000000
44 Correct 1253 ms 94620 KB n=1000000
45 Correct 928 ms 70544 KB n=666666
46 Correct 575 ms 46516 KB n=400000
47 Correct 239 ms 9708 KB n=2336
48 Correct 490 ms 39092 KB n=285714
49 Correct 388 ms 28744 KB n=181818
50 Correct 283 ms 15184 KB n=40000
51 Correct 259 ms 12896 KB n=20000
52 Correct 269 ms 10980 KB n=10000
53 Correct 253 ms 10600 KB n=6666
54 Correct 246 ms 10088 KB n=4000
55 Correct 240 ms 9964 KB n=2857
56 Correct 241 ms 9324 KB n=2000