답안 #634005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634005 2022-08-23T16:13:13 Z drkarlicio2107 Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 200272 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(){
	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 << endl;
	for (int i=0; i<ind; i++){
		for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
		cout << endl;
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:29: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]
   29 |  for (int i=0; i<s.size(); i++){
      |                ~^~~~~~~~~
nicegift.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 70720 KB n=4
2 Correct 34 ms 70704 KB n=3
3 Correct 33 ms 70740 KB n=3
4 Correct 33 ms 70744 KB n=4
5 Correct 34 ms 70752 KB n=4
6 Correct 32 ms 70652 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 70720 KB n=4
2 Correct 34 ms 70704 KB n=3
3 Correct 33 ms 70740 KB n=3
4 Correct 33 ms 70744 KB n=4
5 Correct 34 ms 70752 KB n=4
6 Correct 32 ms 70652 KB n=2
7 Correct 33 ms 70700 KB n=5
8 Correct 32 ms 70740 KB n=8
9 Correct 33 ms 70732 KB n=14
10 Correct 37 ms 70764 KB n=11
11 Correct 118 ms 76032 KB n=50000
12 Correct 123 ms 75956 KB n=50000
13 Correct 33 ms 70748 KB n=10
14 Correct 34 ms 70836 KB n=685
15 Correct 36 ms 70808 KB n=623
16 Correct 41 ms 70784 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 70720 KB n=4
2 Correct 34 ms 70704 KB n=3
3 Correct 33 ms 70740 KB n=3
4 Correct 33 ms 70744 KB n=4
5 Correct 34 ms 70752 KB n=4
6 Correct 32 ms 70652 KB n=2
7 Correct 33 ms 70700 KB n=5
8 Correct 32 ms 70740 KB n=8
9 Correct 33 ms 70732 KB n=14
10 Correct 37 ms 70764 KB n=11
11 Correct 118 ms 76032 KB n=50000
12 Correct 123 ms 75956 KB n=50000
13 Correct 33 ms 70748 KB n=10
14 Correct 34 ms 70836 KB n=685
15 Correct 36 ms 70808 KB n=623
16 Correct 41 ms 70784 KB n=973
17 Correct 36 ms 70748 KB n=989
18 Correct 36 ms 70820 KB n=563
19 Correct 36 ms 70976 KB n=592
20 Correct 36 ms 70968 KB n=938
21 Correct 36 ms 70868 KB n=747
22 Correct 36 ms 70996 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 1734 ms 163448 KB n=1000000
2 Correct 916 ms 134736 KB n=666666
3 Correct 481 ms 108272 KB n=400000
4 Correct 930 ms 130028 KB n=285714
5 Correct 56 ms 72772 KB n=20000
6 Correct 624 ms 124124 KB n=181818
7 Correct 43 ms 71880 KB n=10000
8 Correct 70 ms 77272 KB n=6666
9 Correct 38 ms 71112 KB n=4000
10 Correct 223 ms 103216 KB n=2857
11 Correct 42 ms 70992 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 70720 KB n=4
2 Correct 34 ms 70704 KB n=3
3 Correct 33 ms 70740 KB n=3
4 Correct 33 ms 70744 KB n=4
5 Correct 34 ms 70752 KB n=4
6 Correct 32 ms 70652 KB n=2
7 Correct 33 ms 70700 KB n=5
8 Correct 32 ms 70740 KB n=8
9 Correct 33 ms 70732 KB n=14
10 Correct 37 ms 70764 KB n=11
11 Correct 118 ms 76032 KB n=50000
12 Correct 123 ms 75956 KB n=50000
13 Correct 33 ms 70748 KB n=10
14 Correct 34 ms 70836 KB n=685
15 Correct 36 ms 70808 KB n=623
16 Correct 41 ms 70784 KB n=973
17 Correct 36 ms 70748 KB n=989
18 Correct 36 ms 70820 KB n=563
19 Correct 36 ms 70976 KB n=592
20 Correct 36 ms 70968 KB n=938
21 Correct 36 ms 70868 KB n=747
22 Correct 36 ms 70996 KB n=991
23 Correct 1734 ms 163448 KB n=1000000
24 Correct 916 ms 134736 KB n=666666
25 Correct 481 ms 108272 KB n=400000
26 Correct 930 ms 130028 KB n=285714
27 Correct 56 ms 72772 KB n=20000
28 Correct 624 ms 124124 KB n=181818
29 Correct 43 ms 71880 KB n=10000
30 Correct 70 ms 77272 KB n=6666
31 Correct 38 ms 71112 KB n=4000
32 Correct 223 ms 103216 KB n=2857
33 Correct 42 ms 70992 KB n=2000
34 Correct 81 ms 73576 KB n=23514
35 Correct 88 ms 73660 KB n=23514
36 Correct 42 ms 70856 KB n=940
37 Correct 34 ms 70736 KB n=2
38 Correct 261 ms 87528 KB n=100000
39 Correct 271 ms 87596 KB n=100000
40 Correct 33 ms 70728 KB n=10
41 Correct 34 ms 70704 KB n=100
42 Correct 41 ms 71524 KB n=1000
43 Execution timed out 2084 ms 200272 KB Time limit exceeded
44 Halted 0 ms 0 KB -