# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378770 |
2021-03-17T04:00:37 Z |
8e7 |
Gift (IZhO18_nicegift) |
C++14 |
|
2000 ms |
48352 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];
vector<ll> val;
vector<int> ans[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;
for (int i = 0;i < n;i++) {
if (a[i] > siz) {
poss = false;
break;
}
val.push_back(pref[i] % siz);
}
sort(val.begin(), val.end());
val.push_back(siz);
val.resize(int(unique(val.begin(), val.end()) - val.begin()));
if (!poss) {
cout << -1 << endl;
} else {
int num = 0, ind = 0;
ll cur = 0;
for (int i = 0;i < val.size();i++) {
//cout << val[i] << " " << cur << endl;
if (val[i] - cur > 0) { //[cur, val[i])
ans[num].push_back(val[i] - cur);
while (ind < n && pref[ind] <= cur) ind++;
int id = ind;
for (ll j = cur;j < m;j += siz) {
while (id < n && pref[id] <= j) id++;
if (id < n) ans[num].push_back(id+1);
else {
break;
}
}
cur = val[i];
num++;
}
}
cout << num << "\n";
for (int i = 0;i < num;i++) {
for (int j:ans[i]) cout << j << " ";
cout << "\n";
}
}
}
/*
4 2
2 3 3 2
6 4
4 1 3 5 5 2
*/
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 0;i < val.size();i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=4 |
2 |
Correct |
16 ms |
23788 KB |
n=3 |
3 |
Correct |
17 ms |
23788 KB |
n=3 |
4 |
Correct |
17 ms |
23788 KB |
n=4 |
5 |
Correct |
18 ms |
23788 KB |
n=4 |
6 |
Correct |
16 ms |
23788 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=4 |
2 |
Correct |
16 ms |
23788 KB |
n=3 |
3 |
Correct |
17 ms |
23788 KB |
n=3 |
4 |
Correct |
17 ms |
23788 KB |
n=4 |
5 |
Correct |
18 ms |
23788 KB |
n=4 |
6 |
Correct |
16 ms |
23788 KB |
n=2 |
7 |
Correct |
17 ms |
23788 KB |
n=5 |
8 |
Correct |
17 ms |
23916 KB |
n=8 |
9 |
Correct |
17 ms |
23788 KB |
n=14 |
10 |
Correct |
17 ms |
23788 KB |
n=11 |
11 |
Correct |
438 ms |
27244 KB |
n=50000 |
12 |
Correct |
483 ms |
26968 KB |
n=50000 |
13 |
Correct |
18 ms |
23788 KB |
n=10 |
14 |
Correct |
17 ms |
23888 KB |
n=685 |
15 |
Correct |
17 ms |
23948 KB |
n=623 |
16 |
Correct |
17 ms |
23916 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=4 |
2 |
Correct |
16 ms |
23788 KB |
n=3 |
3 |
Correct |
17 ms |
23788 KB |
n=3 |
4 |
Correct |
17 ms |
23788 KB |
n=4 |
5 |
Correct |
18 ms |
23788 KB |
n=4 |
6 |
Correct |
16 ms |
23788 KB |
n=2 |
7 |
Correct |
17 ms |
23788 KB |
n=5 |
8 |
Correct |
17 ms |
23916 KB |
n=8 |
9 |
Correct |
17 ms |
23788 KB |
n=14 |
10 |
Correct |
17 ms |
23788 KB |
n=11 |
11 |
Correct |
438 ms |
27244 KB |
n=50000 |
12 |
Correct |
483 ms |
26968 KB |
n=50000 |
13 |
Correct |
18 ms |
23788 KB |
n=10 |
14 |
Correct |
17 ms |
23888 KB |
n=685 |
15 |
Correct |
17 ms |
23948 KB |
n=623 |
16 |
Correct |
17 ms |
23916 KB |
n=973 |
17 |
Correct |
18 ms |
23916 KB |
n=989 |
18 |
Correct |
17 ms |
23916 KB |
n=563 |
19 |
Correct |
18 ms |
24044 KB |
n=592 |
20 |
Correct |
19 ms |
24044 KB |
n=938 |
21 |
Correct |
20 ms |
23916 KB |
n=747 |
22 |
Correct |
19 ms |
24044 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2072 ms |
48352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=4 |
2 |
Correct |
16 ms |
23788 KB |
n=3 |
3 |
Correct |
17 ms |
23788 KB |
n=3 |
4 |
Correct |
17 ms |
23788 KB |
n=4 |
5 |
Correct |
18 ms |
23788 KB |
n=4 |
6 |
Correct |
16 ms |
23788 KB |
n=2 |
7 |
Correct |
17 ms |
23788 KB |
n=5 |
8 |
Correct |
17 ms |
23916 KB |
n=8 |
9 |
Correct |
17 ms |
23788 KB |
n=14 |
10 |
Correct |
17 ms |
23788 KB |
n=11 |
11 |
Correct |
438 ms |
27244 KB |
n=50000 |
12 |
Correct |
483 ms |
26968 KB |
n=50000 |
13 |
Correct |
18 ms |
23788 KB |
n=10 |
14 |
Correct |
17 ms |
23888 KB |
n=685 |
15 |
Correct |
17 ms |
23948 KB |
n=623 |
16 |
Correct |
17 ms |
23916 KB |
n=973 |
17 |
Correct |
18 ms |
23916 KB |
n=989 |
18 |
Correct |
17 ms |
23916 KB |
n=563 |
19 |
Correct |
18 ms |
24044 KB |
n=592 |
20 |
Correct |
19 ms |
24044 KB |
n=938 |
21 |
Correct |
20 ms |
23916 KB |
n=747 |
22 |
Correct |
19 ms |
24044 KB |
n=991 |
23 |
Execution timed out |
2072 ms |
48352 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |