#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 200000, logN = 20, K = 48763;
int main () {
owo;
int n, k;
cin >> n >> k;
vector <lli> a(n);
vector <lli> pre = {0};
for (int i = 0; i < n; ++i)
cin >> a[i], pre.pb(pre.back() + a[i]);
if (pre.back() % k) {
cout << -1 << endl;
return 0;
}
lli len = pre.back() / k;
for (lli i : a)
if (len < i) {
cout << -1 << endl;
return 0;
}
vector <lli> split;
for (lli &i : pre)
i %= len, split.pb(i);
sort(all(split));
split.resize(unique(all(split)) - split.begin());
split.pb(len);
int m = split.size();
vector <vector <int>> ans(m);
for (int i = 0; i < n; ++i) {
int from = lower_bound(all(split), pre[i]) - split.begin();
int to = lower_bound(all(split), pre[i + 1]) - split.begin();
for (int j = (from + 1) % m; ; j = (j + 1) % m) {
ans[j].pb(i + 1);
if (j == to)
break;
}
}
cout << m - 1 << endl;
for (int i = 1; i < m; ++i) {
cout << split[i] - split[i - 1] << ' ';
printv(all(ans[i]));
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
204 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
4404 KB |
n=50000 |
12 |
Correct |
27 ms |
4208 KB |
n=50000 |
13 |
Correct |
1 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
4404 KB |
n=50000 |
12 |
Correct |
27 ms |
4208 KB |
n=50000 |
13 |
Correct |
1 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
2 ms |
332 KB |
n=563 |
19 |
Correct |
2 ms |
460 KB |
n=592 |
20 |
Correct |
3 ms |
460 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
2 ms |
460 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
502 ms |
65148 KB |
n=1000000 |
2 |
Correct |
303 ms |
44960 KB |
n=666666 |
3 |
Correct |
185 ms |
24680 KB |
n=400000 |
4 |
Correct |
362 ms |
48240 KB |
n=285714 |
5 |
Correct |
6 ms |
1232 KB |
n=20000 |
6 |
Correct |
383 ms |
40836 KB |
n=181818 |
7 |
Correct |
4 ms |
836 KB |
n=10000 |
8 |
Correct |
29 ms |
4480 KB |
n=6666 |
9 |
Correct |
2 ms |
452 KB |
n=4000 |
10 |
Correct |
161 ms |
21488 KB |
n=2857 |
11 |
Correct |
1 ms |
332 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
4404 KB |
n=50000 |
12 |
Correct |
27 ms |
4208 KB |
n=50000 |
13 |
Correct |
1 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
2 ms |
332 KB |
n=563 |
19 |
Correct |
2 ms |
460 KB |
n=592 |
20 |
Correct |
3 ms |
460 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
2 ms |
460 KB |
n=991 |
23 |
Correct |
502 ms |
65148 KB |
n=1000000 |
24 |
Correct |
303 ms |
44960 KB |
n=666666 |
25 |
Correct |
185 ms |
24680 KB |
n=400000 |
26 |
Correct |
362 ms |
48240 KB |
n=285714 |
27 |
Correct |
6 ms |
1232 KB |
n=20000 |
28 |
Correct |
383 ms |
40836 KB |
n=181818 |
29 |
Correct |
4 ms |
836 KB |
n=10000 |
30 |
Correct |
29 ms |
4480 KB |
n=6666 |
31 |
Correct |
2 ms |
452 KB |
n=4000 |
32 |
Correct |
161 ms |
21488 KB |
n=2857 |
33 |
Correct |
1 ms |
332 KB |
n=2000 |
34 |
Correct |
14 ms |
2556 KB |
n=23514 |
35 |
Correct |
13 ms |
2556 KB |
n=23514 |
36 |
Correct |
1 ms |
312 KB |
n=940 |
37 |
Correct |
0 ms |
308 KB |
n=2 |
38 |
Correct |
91 ms |
13180 KB |
n=100000 |
39 |
Correct |
85 ms |
13112 KB |
n=100000 |
40 |
Correct |
1 ms |
204 KB |
n=10 |
41 |
Correct |
2 ms |
332 KB |
n=100 |
42 |
Correct |
6 ms |
820 KB |
n=1000 |
43 |
Correct |
637 ms |
105928 KB |
n=1000000 |
44 |
Correct |
701 ms |
116868 KB |
n=1000000 |
45 |
Correct |
496 ms |
82612 KB |
n=666666 |
46 |
Correct |
402 ms |
60772 KB |
n=400000 |
47 |
Correct |
174 ms |
18996 KB |
n=2336 |
48 |
Correct |
338 ms |
48072 KB |
n=285714 |
49 |
Correct |
368 ms |
40748 KB |
n=181818 |
50 |
Correct |
228 ms |
25392 KB |
n=40000 |
51 |
Correct |
211 ms |
23012 KB |
n=20000 |
52 |
Correct |
182 ms |
20972 KB |
n=10000 |
53 |
Correct |
162 ms |
24000 KB |
n=6666 |
54 |
Correct |
161 ms |
18072 KB |
n=4000 |
55 |
Correct |
171 ms |
21296 KB |
n=2857 |
56 |
Correct |
165 ms |
16980 KB |
n=2000 |