답안 #378811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378811 2021-03-17T04:59:37 Z 8e7 Gift (IZhO18_nicegift) C++14
100 / 100
790 ms 75292 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 1000005
#define pii pair<int, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll a[maxn], pref[maxn], val[maxn];
ll out[3 * maxn];
bool ed[3 * maxn];
int main() {
	io
	ll n, k;
	cin >> n >> k;
	ll m = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		m += a[i];
		pref[i] = m;
	}

	bool poss = m % k == 0;
	ll siz = m / k;
	int vs = 0;

	for (int i = 0;i < n;i++) {
		if (a[i] > siz) {
			poss = false;
			break;
		}
		val[vs++] = pref[i] % siz;
	}
	val[vs++] = siz;
	sort(val, val + vs);
	if (!poss) {
		cout << -1 << endl;
	} else {
		int num = 0, cnt = 0;
		ll cur = 0;
		for (int i = 0;i < vs;i++) {
			//cout << val[i] << " " << cur << endl;
			if (val[i] - cur > 0) { //[cur, val[i])
				out[num++] = val[i] - cur;
				int ind = upper_bound(pref, pref + n, cur) - pref;
				for (ll j = cur;j < m;j += m / k) {
					ind = upper_bound(pref, pref + n, j) - pref;
					if (ind < n) out[num++] = ind+1;
				}
				ed[num - 1] = true;
				cur = val[i];
				cnt++;
			}
		}
		cout << cnt << "\n";

		for (int i = 0;i < num;i++) {
			cout << out[i] << (ed[i] ? '\n' : ' ');
		}
	}
}
/*
4 2
2 3 3 2

6 4
4 1 3 5 5 2
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 27 ms 3308 KB n=50000
12 Correct 25 ms 3180 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 492 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 27 ms 3308 KB n=50000
12 Correct 25 ms 3180 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 2 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 3 ms 492 KB n=592
20 Correct 3 ms 640 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 2 ms 620 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 51052 KB n=1000000
2 Correct 306 ms 31596 KB n=666666
3 Correct 173 ms 17900 KB n=400000
4 Correct 448 ms 44268 KB n=285714
5 Correct 9 ms 1132 KB n=20000
6 Correct 397 ms 39148 KB n=181818
7 Correct 5 ms 760 KB n=10000
8 Correct 52 ms 5204 KB n=6666
9 Correct 2 ms 492 KB n=4000
10 Correct 253 ms 27372 KB n=2857
11 Correct 1 ms 492 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 27 ms 3308 KB n=50000
12 Correct 25 ms 3180 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 2 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 3 ms 492 KB n=592
20 Correct 3 ms 640 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 2 ms 620 KB n=991
23 Correct 540 ms 51052 KB n=1000000
24 Correct 306 ms 31596 KB n=666666
25 Correct 173 ms 17900 KB n=400000
26 Correct 448 ms 44268 KB n=285714
27 Correct 9 ms 1132 KB n=20000
28 Correct 397 ms 39148 KB n=181818
29 Correct 5 ms 760 KB n=10000
30 Correct 52 ms 5204 KB n=6666
31 Correct 2 ms 492 KB n=4000
32 Correct 253 ms 27372 KB n=2857
33 Correct 1 ms 492 KB n=2000
34 Correct 16 ms 1900 KB n=23514
35 Correct 15 ms 1900 KB n=23514
36 Correct 1 ms 492 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 116 ms 11160 KB n=100000
39 Correct 102 ms 11116 KB n=100000
40 Correct 1 ms 364 KB n=10
41 Correct 1 ms 492 KB n=100
42 Correct 8 ms 1004 KB n=1000
43 Correct 644 ms 70984 KB n=1000000
44 Correct 790 ms 75292 KB n=1000000
45 Correct 593 ms 60496 KB n=666666
46 Correct 503 ms 48364 KB n=400000
47 Correct 252 ms 27244 KB n=2336
48 Correct 427 ms 44252 KB n=285714
49 Correct 376 ms 39052 KB n=181818
50 Correct 320 ms 30956 KB n=40000
51 Correct 264 ms 29676 KB n=20000
52 Correct 252 ms 28268 KB n=10000
53 Correct 251 ms 28012 KB n=6666
54 Correct 245 ms 27500 KB n=4000
55 Correct 252 ms 27372 KB n=2857
56 Correct 249 ms 26476 KB n=2000