Submission #92504

# Submission time Handle Problem Language Result Execution time Memory
92504 2019-01-03T06:40:21 Z Nordway Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 86600 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const int inf = INT_MAX;
const int mod = 998244353;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int N = 1e6+5;
const int M = 1e2+1;

ll a[N],pos[N];

int main(){
	int n,k;
	cin>>n>>k;
	ll sum=0,mx=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
		mx=max(mx,a[i]);	
	}
	ll part=sum/k;
	if(sum%k||mx>part){
		cout<<"-1";
		return 0;
	}
	sum=0;
	vector< vector<pli> >q;
	vector<pli>v;
	for(int i=1;i<=n;i++){
		sum+=a[i];
		if(sum>=part){
			v.pb(mp(a[i]-(sum-part),i));
			q.pb(v);
			v.clear();
			sum-=part;
			if(sum)v.pb(mp(sum,i));
		}
		else v.pb(mp(a[i],i));
	}
	vector<ll>ans;	
	while(1){
		ll mn=1e18;
		for(int i=0;i<k;i++){
			mn=min(mn,q[i][pos[i]].x);
		}
		//cout<<mn<<" ";
		ans.pb(mn);
		bool w=0;
		for(int i=0;i<k;i++){
			//cout<<q[i][pos[i]].y<<" ";
			ans.pb(q[i][pos[i]].y);
			q[i][pos[i]].x-=mn;
			if(pos[i]<sz(q[i])&&!q[i][pos[i]].x){
				pos[i]++;
				if(pos[i]<sz(q[i]))w++;
			}
		}
		if(!w)break;
	}
	cout<<sz(ans)/(k+1)<<endl;
	for(int i=0;i<sz(ans);i++){
		cout<<ans[i]<<" ";
		if((i+1)%(k+1)==0)cout<<endl;
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:73:25: warning: use of an operand of type 'bool' in 'operator++' is deprecated [-Wdeprecated]
     if(pos[i]<sz(q[i]))w++;
                         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 376 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 348 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 78 ms 3948 KB n=50000
12 Correct 73 ms 3664 KB n=50000
13 Correct 2 ms 400 KB n=10
14 Correct 3 ms 380 KB n=685
15 Correct 3 ms 376 KB n=623
16 Correct 4 ms 504 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 348 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 78 ms 3948 KB n=50000
12 Correct 73 ms 3664 KB n=50000
13 Correct 2 ms 400 KB n=10
14 Correct 3 ms 380 KB n=685
15 Correct 3 ms 376 KB n=623
16 Correct 4 ms 504 KB n=973
17 Correct 3 ms 504 KB n=989
18 Correct 3 ms 504 KB n=563
19 Correct 4 ms 632 KB n=592
20 Correct 4 ms 632 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 4 ms 632 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1354 ms 57780 KB n=1000000
2 Correct 736 ms 43456 KB n=666666
3 Correct 365 ms 24252 KB n=400000
4 Correct 788 ms 46664 KB n=285714
5 Correct 15 ms 1528 KB n=20000
6 Correct 573 ms 40388 KB n=181818
7 Correct 9 ms 1020 KB n=10000
8 Correct 40 ms 4956 KB n=6666
9 Correct 5 ms 636 KB n=4000
10 Correct 199 ms 25396 KB n=2857
11 Correct 3 ms 504 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 348 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 78 ms 3948 KB n=50000
12 Correct 73 ms 3664 KB n=50000
13 Correct 2 ms 400 KB n=10
14 Correct 3 ms 380 KB n=685
15 Correct 3 ms 376 KB n=623
16 Correct 4 ms 504 KB n=973
17 Correct 3 ms 504 KB n=989
18 Correct 3 ms 504 KB n=563
19 Correct 4 ms 632 KB n=592
20 Correct 4 ms 632 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 4 ms 632 KB n=991
23 Correct 1354 ms 57780 KB n=1000000
24 Correct 736 ms 43456 KB n=666666
25 Correct 365 ms 24252 KB n=400000
26 Correct 788 ms 46664 KB n=285714
27 Correct 15 ms 1528 KB n=20000
28 Correct 573 ms 40388 KB n=181818
29 Correct 9 ms 1020 KB n=10000
30 Correct 40 ms 4956 KB n=6666
31 Correct 5 ms 636 KB n=4000
32 Correct 199 ms 25396 KB n=2857
33 Correct 3 ms 504 KB n=2000
34 Correct 46 ms 2416 KB n=23514
35 Correct 45 ms 2288 KB n=23514
36 Correct 3 ms 376 KB n=940
37 Correct 2 ms 376 KB n=2
38 Correct 209 ms 11744 KB n=100000
39 Correct 215 ms 11748 KB n=100000
40 Correct 2 ms 376 KB n=10
41 Correct 2 ms 504 KB n=100
42 Correct 8 ms 1136 KB n=1000
43 Execution timed out 2049 ms 86600 KB Time limit exceeded
44 Halted 0 ms 0 KB -