# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
173909 |
2020-01-05T19:13:04 Z |
VEGAnn |
Gift (IZhO18_nicegift) |
C++14 |
|
416 ms |
49600 KB |
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define pli pair<ll, int>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int oo = 2e9;
const ll OO = 1e18;
const int N = 1000100;
set<pli, greater<pli> > st;
vector<vector<ll> > ans;
vector<ll> vc;
int n, k;
ll a[N];
void BAD(){
cout << -1;
exit(0);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
bool ok = 1;
for (int i = 0; i < n; i++){
cin >> a[i];
if (i > 0)
ok &= bool(a[i] == a[i - 1]);
}
if (ok){
int kl = k / __gcd(n, k);
if (a[0] % kl == 0){
int bd = kl * n;
for (int it = 0; it < bd; it += k){
vc.clear();
for (int lit = 0; lit < k; lit++){
int ps = (it + lit) % n;
vc.PB(ps);
}
ans.PB(vc);
}
cout << sz(ans) << '\n';
for (int it = 0; it < sz(ans); it++){
cout << a[0] / kl;
for (ll x : ans[it])
cout << " " << x + 1;
cout << '\n';
}
} else {
cout << -1;
}
return 0;
}
for (int i = 0; i < n; i++){
st.insert(MP(a[i], i));
}
for (ll po = 59; po >= 0; po--){
ll cur = (1ll << po);
while ((*st.begin()).ft > 0){
vc.clear();
vc.PB(cur);
bool was = 0;
for (int it = 0; it < k; it++){
pli cr = (*st.begin());
st.erase(st.begin());
if (cr.ft < cur) {
vc.PB(cr.sd);
was = 1;
break;
}
a[cr.sd] -= cur;
vc.PB(cr.sd);
}
if (was) {
for (int it = 1; it < sz(vc); it++){
int x = vc[it];
if (it < sz(vc) - 1)
a[x] += cur;
st.insert(MP(a[x], x));
}
break;
} else {
ans.PB(vc);
for (int it = 1; it < sz(vc); it++){
int x = vc[it];
st.insert(MP(a[x], x));
}
}
}
}
if ((*st.begin()).ft > 0)
BAD();
cout << sz(ans) << '\n';
for (int it = 0; it < sz(ans); it++){
// cout << "1";
for (int i = 0; i < sz(ans[it]); i++){
if (i == 0)
cout << ans[it][0];
else cout << " " << ans[it][i] + 1;
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
2 ms |
276 KB |
n=14 |
10 |
Correct |
2 ms |
376 KB |
n=11 |
11 |
Correct |
48 ms |
5936 KB |
n=50000 |
12 |
Correct |
43 ms |
5680 KB |
n=50000 |
13 |
Correct |
2 ms |
376 KB |
n=10 |
14 |
Correct |
3 ms |
504 KB |
n=685 |
15 |
Correct |
3 ms |
504 KB |
n=623 |
16 |
Correct |
3 ms |
504 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
2 ms |
276 KB |
n=14 |
10 |
Correct |
2 ms |
376 KB |
n=11 |
11 |
Correct |
48 ms |
5936 KB |
n=50000 |
12 |
Correct |
43 ms |
5680 KB |
n=50000 |
13 |
Correct |
2 ms |
376 KB |
n=10 |
14 |
Correct |
3 ms |
504 KB |
n=685 |
15 |
Correct |
3 ms |
504 KB |
n=623 |
16 |
Correct |
3 ms |
504 KB |
n=973 |
17 |
Correct |
4 ms |
504 KB |
n=989 |
18 |
Correct |
3 ms |
504 KB |
n=563 |
19 |
Correct |
3 ms |
504 KB |
n=592 |
20 |
Correct |
3 ms |
508 KB |
n=938 |
21 |
Correct |
3 ms |
376 KB |
n=747 |
22 |
Correct |
4 ms |
504 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
49600 KB |
n=1000000 |
2 |
Correct |
254 ms |
25500 KB |
n=666666 |
3 |
Correct |
141 ms |
12932 KB |
n=400000 |
4 |
Correct |
326 ms |
44220 KB |
n=285714 |
5 |
Correct |
8 ms |
760 KB |
n=20000 |
6 |
Correct |
281 ms |
38392 KB |
n=181818 |
7 |
Correct |
5 ms |
504 KB |
n=10000 |
8 |
Correct |
34 ms |
4728 KB |
n=6666 |
9 |
Correct |
4 ms |
504 KB |
n=4000 |
10 |
Correct |
186 ms |
25472 KB |
n=2857 |
11 |
Correct |
3 ms |
380 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
2 ms |
276 KB |
n=14 |
10 |
Correct |
2 ms |
376 KB |
n=11 |
11 |
Correct |
48 ms |
5936 KB |
n=50000 |
12 |
Correct |
43 ms |
5680 KB |
n=50000 |
13 |
Correct |
2 ms |
376 KB |
n=10 |
14 |
Correct |
3 ms |
504 KB |
n=685 |
15 |
Correct |
3 ms |
504 KB |
n=623 |
16 |
Correct |
3 ms |
504 KB |
n=973 |
17 |
Correct |
4 ms |
504 KB |
n=989 |
18 |
Correct |
3 ms |
504 KB |
n=563 |
19 |
Correct |
3 ms |
504 KB |
n=592 |
20 |
Correct |
3 ms |
508 KB |
n=938 |
21 |
Correct |
3 ms |
376 KB |
n=747 |
22 |
Correct |
4 ms |
504 KB |
n=991 |
23 |
Correct |
416 ms |
49600 KB |
n=1000000 |
24 |
Correct |
254 ms |
25500 KB |
n=666666 |
25 |
Correct |
141 ms |
12932 KB |
n=400000 |
26 |
Correct |
326 ms |
44220 KB |
n=285714 |
27 |
Correct |
8 ms |
760 KB |
n=20000 |
28 |
Correct |
281 ms |
38392 KB |
n=181818 |
29 |
Correct |
5 ms |
504 KB |
n=10000 |
30 |
Correct |
34 ms |
4728 KB |
n=6666 |
31 |
Correct |
4 ms |
504 KB |
n=4000 |
32 |
Correct |
186 ms |
25472 KB |
n=2857 |
33 |
Correct |
3 ms |
380 KB |
n=2000 |
34 |
Correct |
83 ms |
7812 KB |
n=23514 |
35 |
Correct |
91 ms |
7840 KB |
n=23514 |
36 |
Correct |
3 ms |
504 KB |
n=940 |
37 |
Correct |
2 ms |
376 KB |
n=2 |
38 |
Correct |
231 ms |
16392 KB |
n=100000 |
39 |
Correct |
229 ms |
16420 KB |
n=100000 |
40 |
Incorrect |
2 ms |
376 KB |
Jury has the answer but participant has not |
41 |
Halted |
0 ms |
0 KB |
- |