답안 #634016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634016 2022-08-23T16:30:22 Z drkarlicio2107 Gift (IZhO18_nicegift) C++14
100 / 100
924 ms 198384 KB
#include <bits/stdc++.h>
using namespace std;
vector < pair <long long int, pair<long long int, long long int> > > s;
set <long long int> m;
long long int a [1000010];
vector <long long int> ans [3000010];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n, k; cin >> n >> k; long long int gr=0; long long int sum=0;
	for (int i=0; i<n; i++){
		long long int x; cin >> x; a[i]=x; sum+=a[i];
	}
	for (int i=0; i<n; i++){
		long long int x=a[i];
		s.push_back ({(gr)%(sum/k), {i, 0}});	gr+=x;
		//cout << gr << endl;
		if (gr%(sum/k)==0) s.push_back ({sum/k, {i, 1}});
		else s.push_back ({(gr)%(sum/k), {i, 1}});
		if ((gr-x)%(sum/k)>gr%(sum/k) && gr%(sum/k)!=0){
			s.push_back ({0, {i, 0}});
			s.push_back ({sum/k, {i, 1}});
		}
	}
	if (gr%k!=0){
		cout << -1; return 0;
	}
	long long int ind=0;
	for (int i=0; i<n; i++) if (a[i]>gr/k) {cout << -1; return 0;};
	sort (s.begin(), s.end()); long long int pr=0;
	for (int i=0; i<s.size(); i++){
		long long int x=s [i].first; long long int y=s[i].second.first; long long int t=s[i].second.second;
		//cout << x << " " << y << " " << t << endl;
		if (t==0){
			if (x-pr!=0){
				ans [ind].push_back (x-pr);
				for (auto e:m){
					ans [ind].push_back (e+1);
				}
				ind++;
			}
			m.insert (y);
		}
		else{
			if (x-pr!=0){
				ans [ind].push_back (x-pr);
				for (auto e:m){
					ans [ind].push_back (e+1);
				}
				ind++;
			}
			m.erase (y);
		}
		pr=x;
	}
	cout << ind << "\n";
	for (int i=0; i<ind; i++){
		for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
		cout << "\n";
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for (int i=0; i<s.size(); i++){
      |                ~^~~~~~~~~
nicegift.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB n=4
2 Correct 33 ms 70732 KB n=3
3 Correct 34 ms 70864 KB n=3
4 Correct 38 ms 70708 KB n=4
5 Correct 33 ms 70692 KB n=4
6 Correct 35 ms 70688 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB n=4
2 Correct 33 ms 70732 KB n=3
3 Correct 34 ms 70864 KB n=3
4 Correct 38 ms 70708 KB n=4
5 Correct 33 ms 70692 KB n=4
6 Correct 35 ms 70688 KB n=2
7 Correct 33 ms 70732 KB n=5
8 Correct 35 ms 70752 KB n=8
9 Correct 33 ms 70716 KB n=14
10 Correct 33 ms 70744 KB n=11
11 Correct 60 ms 76024 KB n=50000
12 Correct 64 ms 75960 KB n=50000
13 Correct 40 ms 70768 KB n=10
14 Correct 41 ms 70804 KB n=685
15 Correct 35 ms 70764 KB n=623
16 Correct 34 ms 70832 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB n=4
2 Correct 33 ms 70732 KB n=3
3 Correct 34 ms 70864 KB n=3
4 Correct 38 ms 70708 KB n=4
5 Correct 33 ms 70692 KB n=4
6 Correct 35 ms 70688 KB n=2
7 Correct 33 ms 70732 KB n=5
8 Correct 35 ms 70752 KB n=8
9 Correct 33 ms 70716 KB n=14
10 Correct 33 ms 70744 KB n=11
11 Correct 60 ms 76024 KB n=50000
12 Correct 64 ms 75960 KB n=50000
13 Correct 40 ms 70768 KB n=10
14 Correct 41 ms 70804 KB n=685
15 Correct 35 ms 70764 KB n=623
16 Correct 34 ms 70832 KB n=973
17 Correct 38 ms 70888 KB n=989
18 Correct 34 ms 70852 KB n=563
19 Correct 35 ms 70988 KB n=592
20 Correct 37 ms 70964 KB n=938
21 Correct 35 ms 70944 KB n=747
22 Correct 35 ms 70904 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 163524 KB n=1000000
2 Correct 371 ms 125564 KB n=666666
3 Correct 229 ms 102836 KB n=400000
4 Correct 355 ms 126080 KB n=285714
5 Correct 43 ms 72564 KB n=20000
6 Correct 320 ms 121688 KB n=181818
7 Correct 48 ms 71752 KB n=10000
8 Correct 64 ms 77264 KB n=6666
9 Correct 38 ms 71156 KB n=4000
10 Correct 193 ms 103276 KB n=2857
11 Correct 37 ms 70860 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70740 KB n=4
2 Correct 33 ms 70732 KB n=3
3 Correct 34 ms 70864 KB n=3
4 Correct 38 ms 70708 KB n=4
5 Correct 33 ms 70692 KB n=4
6 Correct 35 ms 70688 KB n=2
7 Correct 33 ms 70732 KB n=5
8 Correct 35 ms 70752 KB n=8
9 Correct 33 ms 70716 KB n=14
10 Correct 33 ms 70744 KB n=11
11 Correct 60 ms 76024 KB n=50000
12 Correct 64 ms 75960 KB n=50000
13 Correct 40 ms 70768 KB n=10
14 Correct 41 ms 70804 KB n=685
15 Correct 35 ms 70764 KB n=623
16 Correct 34 ms 70832 KB n=973
17 Correct 38 ms 70888 KB n=989
18 Correct 34 ms 70852 KB n=563
19 Correct 35 ms 70988 KB n=592
20 Correct 37 ms 70964 KB n=938
21 Correct 35 ms 70944 KB n=747
22 Correct 35 ms 70904 KB n=991
23 Correct 729 ms 163524 KB n=1000000
24 Correct 371 ms 125564 KB n=666666
25 Correct 229 ms 102836 KB n=400000
26 Correct 355 ms 126080 KB n=285714
27 Correct 43 ms 72564 KB n=20000
28 Correct 320 ms 121688 KB n=181818
29 Correct 48 ms 71752 KB n=10000
30 Correct 64 ms 77264 KB n=6666
31 Correct 38 ms 71156 KB n=4000
32 Correct 193 ms 103276 KB n=2857
33 Correct 37 ms 70860 KB n=2000
34 Correct 56 ms 73548 KB n=23514
35 Correct 49 ms 73536 KB n=23514
36 Correct 34 ms 70796 KB n=940
37 Correct 33 ms 70696 KB n=2
38 Correct 125 ms 87196 KB n=100000
39 Correct 123 ms 87260 KB n=100000
40 Correct 37 ms 70768 KB n=10
41 Correct 35 ms 70824 KB n=100
42 Correct 40 ms 71468 KB n=1000
43 Correct 676 ms 194264 KB n=1000000
44 Correct 924 ms 198384 KB n=1000000
45 Correct 541 ms 169240 KB n=666666
46 Correct 446 ms 147364 KB n=400000
47 Correct 185 ms 98828 KB n=2336
48 Correct 377 ms 129944 KB n=285714
49 Correct 307 ms 124340 KB n=181818
50 Correct 212 ms 105956 KB n=40000
51 Correct 196 ms 103608 KB n=20000
52 Correct 183 ms 101564 KB n=10000
53 Correct 221 ms 107868 KB n=6666
54 Correct 187 ms 96508 KB n=4000
55 Correct 193 ms 103244 KB n=2857
56 Correct 188 ms 95508 KB n=2000