# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
287951 |
2020-09-01T07:11:34 Z |
Berted |
Gift (IZhO18_nicegift) |
C++14 |
|
476 ms |
76900 KB |
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#include <assert.h>
#define ll long long
#define vi vector<int>
#define piv pair<ll, vector<int>>
#define pii pair<ll, int>
#define fst first
#define snd second
using namespace std;
int N, K;
ll S = 0;
pii A[1000001];
list<piv> L;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("A.in", "r", stdin);
//freopen("A.out", "w", stdout);
cin >> N >> K;
for (int i = 0; i < N; i++) {cin >> A[i].fst; A[i].snd = i; S += A[i].fst;}
if (S % K) {cout << "-1\n";}
else
{
sort(A, A + N, greater<pii>()); S /= K;
if (A[0].fst <= S)
{
L.push_back({S, vi()});
auto it = L.begin();
int iterated = 0;
for (int i = 0; i < N; i++)
{
while (A[i].fst)
{
if (it -> fst > A[i].fst)
{
it -> fst -= A[i].fst;
vector<int> cpy = it -> snd;
cpy.push_back(A[i].snd + 1);
L.insert(it, make_pair(A[i].fst, cpy));
A[i].fst = 0;
}
else
{
A[i].fst -= it -> fst;
it -> snd.push_back(A[i].snd + 1);
it = next(it);
if (it == L.end()) {it = L.begin();}
}
iterated++;
}
}
cout << L.size() << "\n";
for (const auto &x : L)
{
cout << x.fst;
for (const auto &y : x.snd) {cout << " " << y;}
cout << "\n";
}
//cout << "Iteration Calls : " << iterated << "\n";
assert(iterated <= N * K / gcd(N, K));
}
else {cout << "-1\n";}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
476 ms |
76900 KB |
n=1000000 |
2 |
Correct |
269 ms |
39292 KB |
n=666666 |
3 |
Correct |
150 ms |
21752 KB |
n=400000 |
4 |
Correct |
372 ms |
59640 KB |
n=285714 |
5 |
Correct |
6 ms |
896 KB |
n=20000 |
6 |
Correct |
312 ms |
47224 KB |
n=181818 |
7 |
Correct |
4 ms |
640 KB |
n=10000 |
8 |
Correct |
35 ms |
4088 KB |
n=6666 |
9 |
Correct |
2 ms |
384 KB |
n=4000 |
10 |
Correct |
193 ms |
22008 KB |
n=2857 |
11 |
Correct |
1 ms |
384 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |