답안 #335610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335610 2020-12-13T09:30:59 Z amunduzbaev Gift (IZhO18_nicegift) C++14
30 / 100
247 ms 88144 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define int long long
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 5e5+5;
vector<pll> ans[N];
vector<int> aa[N];
int a[N];

void solve(){
	
	int n, k, sum = 0, mx = 0;
	bool f = 1;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
		mx  = max(a[i], mx);
	}
	if(sum % k != 0 || sum / k < mx){
		cout<<-1<<"\n";
		return;
	}
	int cur = 0, cnt = 0, tmp = sum / k;
	for(int i=0;i<n;i++){
		if(cur + a[i] >= tmp){
			ans[cnt++].pb({tmp - cur, i+1});
			cur = cur + a[i] - tmp;
			if(cur) ans[cnt].pb({cur, i+1});
		}else{
			cur += a[i];
			ans[cnt].pb({a[i], i+1});
		}
	}
	cnt = 0;
	while(f){
		int mn = 9e18;
		for(int i=0; i<k; i++)
			mn = min(ans[i][sz(ans[i]) -1].ff, mn);
		aa[cnt].pb(mn);
		f = 1;
      	for(int i=0; i<k; i++){
			pll tmp1 = ans[i][sz(ans[i]) -1];
			ans[i].pop_back();
			tmp1.ff -= mn;
			aa[cnt].pb(tmp1.ss);
			if(tmp1.ff) ans[i].pb(tmp1);
			f &= (!ans[0].empty());
		}
		
		cnt++;
	}
	cout<<cnt<<"\n";
	for(int i=0; i<cnt; i++){
		for(int j=0; j<sz(aa[i]); j++){
			cout<<aa[i][j]<<" ";
		}cout<<"\n";
	}
	
	return;
}


main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

Compilation message

nicegift.cpp:80:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   80 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 16 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 16 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23808 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 17 ms 23788 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 41 ms 27752 KB n=50000
12 Correct 42 ms 27632 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 16 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23808 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 17 ms 23788 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 41 ms 27752 KB n=50000
12 Correct 42 ms 27632 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 18 ms 23916 KB n=989
18 Correct 17 ms 23936 KB n=563
19 Correct 19 ms 24044 KB n=592
20 Correct 19 ms 24044 KB n=938
21 Correct 18 ms 24044 KB n=747
22 Correct 18 ms 24044 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Runtime error 247 ms 88144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 16 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23808 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 17 ms 23788 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 41 ms 27752 KB n=50000
12 Correct 42 ms 27632 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 18 ms 23916 KB n=989
18 Correct 17 ms 23936 KB n=563
19 Correct 19 ms 24044 KB n=592
20 Correct 19 ms 24044 KB n=938
21 Correct 18 ms 24044 KB n=747
22 Correct 18 ms 24044 KB n=991
23 Runtime error 247 ms 88144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -