답안 #378855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378855 2021-03-17T06:16:26 Z casperwang Gift (IZhO18_nicegift) C++14
100 / 100
928 ms 90392 KB
#include <bits/stdc++.h>
#define int long long
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 1000000;
int N, K;
int v[MAXN+1];
int sum, mmax;
vector <pii> arr;
set <int> num;
vector <int> ans;

void update(int x) {
	if (x > 0)
		num.erase(x);
	else
		num.insert(-x);
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		sum += v[i];
		mmax = max(mmax, v[i]);
	}
	if (sum % K || mmax > sum / K) {
		cout << -1 << '\n';
	} else {
		int now = 0;
		for (int i = 1; i <= N; i++) {
			arr.pb(now, -i);
			now += v[i];
			if (now > sum / K) {
				arr.pb(sum / K, i);
				now -= sum / K;
				arr.pb(0, -i);
			}
			arr.pb(now, i);
		}
		sort(All(arr));
		int pre;
		for (int i = 0; i < arr.size(); i++) {
			if (i) {
				ans.pb(arr[i].ff - pre);
				for (int j : num) ans.pb(j);
			}
			pre = arr[i].ff;
			update(arr[i].ss);
			while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
				update(arr[++i].ss);
			}
		}
		cout << ans.size() / (K+1) << '\n';
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i] << " \n"[i%(K+1)==K];
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int i = 0; i < arr.size(); i++) {
      |                   ~~^~~~~~~~~~~~
nicegift.cpp:60:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
      |           ~~~~^~~~~~~~~~~~
nicegift.cpp:65:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for (int i = 0; i < ans.size(); i++)
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 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 0 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 31 ms 4964 KB n=50000
12 Correct 28 ms 4836 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 492 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 0 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 31 ms 4964 KB n=50000
12 Correct 28 ms 4836 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 492 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 1 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 2 ms 620 KB n=592
20 Correct 2 ms 748 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 2 ms 620 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 743 ms 81688 KB n=1000000
2 Correct 368 ms 49304 KB n=666666
3 Correct 225 ms 27708 KB n=400000
4 Correct 408 ms 46592 KB n=285714
5 Correct 12 ms 1644 KB n=20000
6 Correct 345 ms 40592 KB n=181818
7 Correct 7 ms 1008 KB n=10000
8 Correct 41 ms 5088 KB n=6666
9 Correct 3 ms 748 KB n=4000
10 Correct 219 ms 25716 KB n=2857
11 Correct 2 ms 620 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 31 ms 4964 KB n=50000
12 Correct 28 ms 4836 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 492 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 492 KB n=973
17 Correct 1 ms 492 KB n=989
18 Correct 1 ms 492 KB n=563
19 Correct 2 ms 620 KB n=592
20 Correct 2 ms 748 KB n=938
21 Correct 2 ms 492 KB n=747
22 Correct 2 ms 620 KB n=991
23 Correct 743 ms 81688 KB n=1000000
24 Correct 368 ms 49304 KB n=666666
25 Correct 225 ms 27708 KB n=400000
26 Correct 408 ms 46592 KB n=285714
27 Correct 12 ms 1644 KB n=20000
28 Correct 345 ms 40592 KB n=181818
29 Correct 7 ms 1008 KB n=10000
30 Correct 41 ms 5088 KB n=6666
31 Correct 3 ms 748 KB n=4000
32 Correct 219 ms 25716 KB n=2857
33 Correct 2 ms 620 KB n=2000
34 Correct 17 ms 2792 KB n=23514
35 Correct 18 ms 2920 KB n=23514
36 Correct 1 ms 492 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 101 ms 13060 KB n=100000
39 Correct 100 ms 13024 KB n=100000
40 Correct 1 ms 364 KB n=10
41 Correct 1 ms 492 KB n=100
42 Correct 6 ms 1128 KB n=1000
43 Correct 664 ms 90392 KB n=1000000
44 Correct 928 ms 90240 KB n=1000000
45 Correct 568 ms 77208 KB n=666666
46 Correct 463 ms 53888 KB n=400000
47 Correct 222 ms 25748 KB n=2336
48 Correct 404 ms 48256 KB n=285714
49 Correct 348 ms 41372 KB n=181818
50 Correct 244 ms 30268 KB n=40000
51 Correct 232 ms 28396 KB n=20000
52 Correct 222 ms 26684 KB n=10000
53 Correct 223 ms 26452 KB n=6666
54 Correct 218 ms 25916 KB n=4000
55 Correct 218 ms 25844 KB n=2857
56 Correct 212 ms 24864 KB n=2000