#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int, 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 = 100100;
set<pii, greater<pii> > st;
vector<vector<int> > ans;
vector<int> vc;
int n, k, sm;
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]);
sm += a[i];
st.insert(MP(a[i], i));
}
if (ok){
return -1;
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 (int x : ans[it])
cout << " " << x + 1;
cout << '\n';
}
} else {
cout << -1;
}
return 0;
}
while (sm > 0){
vc.clear();
for (int it = 0; it < k; it++){
pii cr = (*st.begin());
st.erase(st.begin());
if (cr.ft == 0)
BAD();
a[cr.sd]--;
sm--;
vc.PB(cr.sd);
}
ans.PB(vc);
for (int x : vc)
st.insert(MP(a[x], x));
}
cout << sz(ans) << '\n';
for (int it = 0; it < sz(ans); it++){
cout << "1";
for (int x : ans[it])
cout << " " << x + 1;
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
256 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
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 |
256 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
252 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
3 ms |
1016 KB |
n=11 |
11 |
Correct |
56 ms |
6572 KB |
n=50000 |
12 |
Correct |
58 ms |
6540 KB |
n=50000 |
13 |
Correct |
26 ms |
3496 KB |
n=10 |
14 |
Correct |
28 ms |
3140 KB |
n=685 |
15 |
Correct |
29 ms |
3368 KB |
n=623 |
16 |
Correct |
18 ms |
2096 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
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 |
256 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
252 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
3 ms |
1016 KB |
n=11 |
11 |
Correct |
56 ms |
6572 KB |
n=50000 |
12 |
Correct |
58 ms |
6540 KB |
n=50000 |
13 |
Correct |
26 ms |
3496 KB |
n=10 |
14 |
Correct |
28 ms |
3140 KB |
n=685 |
15 |
Correct |
29 ms |
3368 KB |
n=623 |
16 |
Correct |
18 ms |
2096 KB |
n=973 |
17 |
Correct |
30 ms |
2608 KB |
n=989 |
18 |
Correct |
14 ms |
1144 KB |
n=563 |
19 |
Correct |
22 ms |
1400 KB |
n=592 |
20 |
Correct |
23 ms |
1400 KB |
n=938 |
21 |
Correct |
17 ms |
1148 KB |
n=747 |
22 |
Correct |
20 ms |
1272 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2062 ms |
53100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
256 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
252 KB |
n=5 |
8 |
Correct |
5 ms |
1016 KB |
n=8 |
9 |
Correct |
10 ms |
1204 KB |
n=14 |
10 |
Correct |
3 ms |
1016 KB |
n=11 |
11 |
Correct |
56 ms |
6572 KB |
n=50000 |
12 |
Correct |
58 ms |
6540 KB |
n=50000 |
13 |
Correct |
26 ms |
3496 KB |
n=10 |
14 |
Correct |
28 ms |
3140 KB |
n=685 |
15 |
Correct |
29 ms |
3368 KB |
n=623 |
16 |
Correct |
18 ms |
2096 KB |
n=973 |
17 |
Correct |
30 ms |
2608 KB |
n=989 |
18 |
Correct |
14 ms |
1144 KB |
n=563 |
19 |
Correct |
22 ms |
1400 KB |
n=592 |
20 |
Correct |
23 ms |
1400 KB |
n=938 |
21 |
Correct |
17 ms |
1148 KB |
n=747 |
22 |
Correct |
20 ms |
1272 KB |
n=991 |
23 |
Execution timed out |
2062 ms |
53100 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |