# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378997 |
2021-03-17T08:16:33 Z |
wiwiho |
Gift (IZhO18_nicegift) |
C++14 |
|
533 ms |
119520 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
ostream& operator<<(ostream& o, pll p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll iceil(ll a, ll b){
return (a + b - 1) / b;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<ll> pos(n + 1), a(n + 1);
ll sum = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
if(sum % k){
cout << "-1\n";
return 0;
}
ll len = sum / k;
ll now = 0;
vector<ll> t;
for(int i = 1; i <= n; i++){
if(a[i] > len){
cout << "-1\n";
return 0;
}
now += a[i];
pos[i] = (now - 1) % len;
t.eb(pos[i]);
}
sort(t.begin(), t.end());
t.resize(unique(t.begin(), t.end()) - t.begin());
len = t.size();
vector<vector<int>> ans(len);
int j = -1;
for(int i = 1; i <= n; i++){
int id = lower_bound(t.begin(), t.end(), pos[i]) - t.begin();
for(j = (j + 1) % len; ; j = (j + 1) % len){
ans[j].eb(i);
if(j == id) break;
}
}
vector<ll> cnt(n + 1);
for(int i = 0; i < len; i++){
for(int j : ans[i]){
cnt[j]++;
}
}
for(int i = 1; i <= n; i++) assert(cnt[i] == a[i]);
cout << len << "\n";
int lst = -1;
for(int i = 0; i < len; i++){
cout << t[i] - lst << " " ;
printv(ans[i], cout);
lst = t[i];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
533 ms |
119520 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |