답안 #489763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489763 2021-11-24T14:09:37 Z luka1234 Gift (IZhO18_nicegift) C++14
100 / 100
933 ms 156752 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m;
ll a[1000001];
ll sum=0;
ll mx=0;
int main(){
	cin>>n>>m;
	vector<int> index(m+1,0);
	vector<vector<pair<ll,ll> > > blocks(n+1);
	vector<vector<ll> > ans(n+1);
	for(int k=1;k<=n;k++){
		cin>>a[k];
		sum+=a[k];
		mx=max(mx,a[k]);
	}
	if(sum%m!=0||mx>sum/m){
		cout<<-1;
		return 0;
	}
	int ind=1;
	for(int k=1;k<=m;k++){
		ll sz=sum/m;
		while(sz>0){
			ll f=a[ind];
			if(sz>=f){
				sz-=f;
				blocks[k].push_back({f,ind});
				ind++;
			}
			else{
				a[ind]-=sz;
				blocks[k].push_back({sz,ind});
				sz=0;
			}
		}
	}
	ind=0;
	while(index[1]<blocks[1].size()){
		ll mn=1e18;
		for(int k=1;k<=m;k++){
			mn=min(mn,blocks[k][index[k]].ff);
		}
		ans[ind].push_back(mn);
		for(int k=1;k<=m;k++){
			int bb=blocks[k][index[k]].ss;
			ans[ind].push_back(blocks[k][index[k]].ss);
		}
		for(int k=1;k<=m;k++){
			blocks[k][index[k]].ff-=mn;
			if(blocks[k][index[k]].ff==0){
				index[k]++;
			}
		}
		ind++;
	}
	cout<<ind<<"\n";
	for(int k=0;k<ind;k++){
		for(int i=0;i<ans[k].size();i++){
			cout<<ans[k][i]<<' ';
		}
		cout<<"\n";
	}
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:42:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  while(index[1]<blocks[1].size()){
nicegift.cpp:49:8: warning: unused variable 'bb' [-Wunused-variable]
   49 |    int bb=blocks[k][index[k]].ss;
      |        ^~
nicegift.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int i=0;i<ans[k].size();i++){
      |               ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 0 ms 208 KB n=3
4 Correct 0 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 0 ms 208 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 0 ms 208 KB n=3
4 Correct 0 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 0 ms 208 KB n=2
7 Correct 1 ms 208 KB n=5
8 Correct 0 ms 208 KB n=8
9 Correct 1 ms 208 KB n=14
10 Correct 1 ms 304 KB n=11
11 Correct 37 ms 6456 KB n=50000
12 Correct 26 ms 6348 KB n=50000
13 Correct 0 ms 208 KB n=10
14 Correct 1 ms 336 KB n=685
15 Correct 1 ms 336 KB n=623
16 Correct 1 ms 336 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 0 ms 208 KB n=3
4 Correct 0 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 0 ms 208 KB n=2
7 Correct 1 ms 208 KB n=5
8 Correct 0 ms 208 KB n=8
9 Correct 1 ms 208 KB n=14
10 Correct 1 ms 304 KB n=11
11 Correct 37 ms 6456 KB n=50000
12 Correct 26 ms 6348 KB n=50000
13 Correct 0 ms 208 KB n=10
14 Correct 1 ms 336 KB n=685
15 Correct 1 ms 336 KB n=623
16 Correct 1 ms 336 KB n=973
17 Correct 1 ms 336 KB n=989
18 Correct 1 ms 336 KB n=563
19 Correct 2 ms 464 KB n=592
20 Correct 2 ms 464 KB n=938
21 Correct 2 ms 464 KB n=747
22 Correct 2 ms 464 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 727 ms 108712 KB n=1000000
2 Correct 453 ms 74720 KB n=666666
3 Correct 266 ms 44052 KB n=400000
4 Correct 411 ms 63996 KB n=285714
5 Correct 13 ms 2384 KB n=20000
6 Correct 361 ms 56592 KB n=181818
7 Correct 7 ms 1256 KB n=10000
8 Correct 43 ms 7048 KB n=6666
9 Correct 3 ms 720 KB n=4000
10 Correct 181 ms 32740 KB n=2857
11 Correct 2 ms 464 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 0 ms 208 KB n=3
4 Correct 0 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 0 ms 208 KB n=2
7 Correct 1 ms 208 KB n=5
8 Correct 0 ms 208 KB n=8
9 Correct 1 ms 208 KB n=14
10 Correct 1 ms 304 KB n=11
11 Correct 37 ms 6456 KB n=50000
12 Correct 26 ms 6348 KB n=50000
13 Correct 0 ms 208 KB n=10
14 Correct 1 ms 336 KB n=685
15 Correct 1 ms 336 KB n=623
16 Correct 1 ms 336 KB n=973
17 Correct 1 ms 336 KB n=989
18 Correct 1 ms 336 KB n=563
19 Correct 2 ms 464 KB n=592
20 Correct 2 ms 464 KB n=938
21 Correct 2 ms 464 KB n=747
22 Correct 2 ms 464 KB n=991
23 Correct 727 ms 108712 KB n=1000000
24 Correct 453 ms 74720 KB n=666666
25 Correct 266 ms 44052 KB n=400000
26 Correct 411 ms 63996 KB n=285714
27 Correct 13 ms 2384 KB n=20000
28 Correct 361 ms 56592 KB n=181818
29 Correct 7 ms 1256 KB n=10000
30 Correct 43 ms 7048 KB n=6666
31 Correct 3 ms 720 KB n=4000
32 Correct 181 ms 32740 KB n=2857
33 Correct 2 ms 464 KB n=2000
34 Correct 19 ms 3616 KB n=23514
35 Correct 18 ms 3516 KB n=23514
36 Correct 2 ms 336 KB n=940
37 Correct 0 ms 208 KB n=2
38 Correct 92 ms 18736 KB n=100000
39 Correct 96 ms 18832 KB n=100000
40 Correct 0 ms 208 KB n=10
41 Correct 1 ms 336 KB n=100
42 Correct 5 ms 1008 KB n=1000
43 Correct 873 ms 146116 KB n=1000000
44 Correct 933 ms 156752 KB n=1000000
45 Correct 665 ms 109240 KB n=666666
46 Correct 496 ms 83196 KB n=400000
47 Correct 195 ms 28340 KB n=2336
48 Correct 394 ms 64040 KB n=285714
49 Correct 332 ms 56556 KB n=181818
50 Correct 216 ms 36292 KB n=40000
51 Correct 198 ms 33480 KB n=20000
52 Correct 191 ms 31208 KB n=10000
53 Correct 181 ms 37504 KB n=6666
54 Correct 173 ms 26068 KB n=4000
55 Correct 185 ms 32876 KB n=2857
56 Correct 165 ms 24904 KB n=2000