# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
379399 |
2021-03-18T06:26:00 Z |
fhvirus |
Gift (IZhO18_nicegift) |
C++17 |
|
996 ms |
215104 KB |
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FOO(i,a,b) for(int i=(a);i<=int(b);++i)
#define OOF(i,a,b) for(int i=(a);i>=int(b);--i)
#define AI(x) begin(x),end(x)
template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;}
template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;}
inline ll cdiv(ll x,ll m){return x/m+(x%m?(x<0)^(m>0):0);}
#ifdef OWO
#define safe cerr<<"\033[1;32m"<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<" JIZZ\033[0m\n"
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
#else
#pragma GCC optimize("Ofast")
#define safe ((void)0)
#define debug(...) ((void)0)
#endif
const ll inf = 1e9, INF = 4e18;
const int N = 1e6 + 225;
int n, k;
ll a[N];
inline void fail(){ puts("-1"); exit(0);}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
FOR(i,n) cin >> a[i];
ll sum = accumulate(a, a + n, 0ll), y = sum / k;
if(y * k != sum) fail();
if(*max_element(a, a + n) > y) fail();
map<ll, vector<pll>> ms;
{
ll cur = 0;
ll x = 0;
FOR(i,n){
ll l = cur, r = cur + a[i] - 1;
debug(a[i], cur, x, l, r);
if(r >= y){
ms[l].pb(x, i);
++x;
ms[0].pb(x, i);
r -= y;
} else {
ms[l].pb(x, i);
}
cur = r + 1;
}
}
debug(ms);
vector<pair<ll, vector<int>>> ans;
vector<int> cur(k);
{
for(auto it = begin(ms); it != end(ms); ++it){
auto [x, mod] = *it;
if(x == y) break;
for(auto [p, i]: mod){
cur[p] = i;
}
ll nx = y;
if(next(it) != end(ms)) nx = (*next(it)).ff;
ans.pb(nx - x, cur);
debug(x, cur);
}
}
cout << ans.size() << '\n';
for(auto [x, v]: ans){
cout << x << ' ';
for(int i: v) cout << i + 1 << ' ';
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
38 ms |
8864 KB |
n=50000 |
12 |
Correct |
37 ms |
8540 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
38 ms |
8864 KB |
n=50000 |
12 |
Correct |
37 ms |
8540 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
2 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
620 KB |
n=592 |
20 |
Correct |
3 ms |
620 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
2 ms |
620 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
719 ms |
116924 KB |
n=1000000 |
2 |
Correct |
410 ms |
62408 KB |
n=666666 |
3 |
Correct |
242 ms |
30316 KB |
n=400000 |
4 |
Correct |
455 ms |
73584 KB |
n=285714 |
5 |
Correct |
7 ms |
1516 KB |
n=20000 |
6 |
Correct |
342 ms |
56748 KB |
n=181818 |
7 |
Correct |
4 ms |
876 KB |
n=10000 |
8 |
Correct |
38 ms |
3820 KB |
n=6666 |
9 |
Correct |
2 ms |
620 KB |
n=4000 |
10 |
Correct |
180 ms |
18028 KB |
n=2857 |
11 |
Correct |
1 ms |
492 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
38 ms |
8864 KB |
n=50000 |
12 |
Correct |
37 ms |
8540 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
2 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
620 KB |
n=592 |
20 |
Correct |
3 ms |
620 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
2 ms |
620 KB |
n=991 |
23 |
Correct |
719 ms |
116924 KB |
n=1000000 |
24 |
Correct |
410 ms |
62408 KB |
n=666666 |
25 |
Correct |
242 ms |
30316 KB |
n=400000 |
26 |
Correct |
455 ms |
73584 KB |
n=285714 |
27 |
Correct |
7 ms |
1516 KB |
n=20000 |
28 |
Correct |
342 ms |
56748 KB |
n=181818 |
29 |
Correct |
4 ms |
876 KB |
n=10000 |
30 |
Correct |
38 ms |
3820 KB |
n=6666 |
31 |
Correct |
2 ms |
620 KB |
n=4000 |
32 |
Correct |
180 ms |
18028 KB |
n=2857 |
33 |
Correct |
1 ms |
492 KB |
n=2000 |
34 |
Correct |
21 ms |
5088 KB |
n=23514 |
35 |
Correct |
20 ms |
5088 KB |
n=23514 |
36 |
Correct |
1 ms |
492 KB |
n=940 |
37 |
Correct |
1 ms |
364 KB |
n=2 |
38 |
Correct |
113 ms |
21848 KB |
n=100000 |
39 |
Correct |
114 ms |
21848 KB |
n=100000 |
40 |
Correct |
1 ms |
364 KB |
n=10 |
41 |
Correct |
1 ms |
364 KB |
n=100 |
42 |
Correct |
7 ms |
876 KB |
n=1000 |
43 |
Correct |
955 ms |
208976 KB |
n=1000000 |
44 |
Correct |
996 ms |
215104 KB |
n=1000000 |
45 |
Correct |
729 ms |
151056 KB |
n=666666 |
46 |
Correct |
505 ms |
95668 KB |
n=400000 |
47 |
Correct |
189 ms |
17772 KB |
n=2336 |
48 |
Correct |
419 ms |
77492 KB |
n=285714 |
49 |
Correct |
362 ms |
56648 KB |
n=181818 |
50 |
Correct |
239 ms |
26972 KB |
n=40000 |
51 |
Correct |
202 ms |
22880 KB |
n=20000 |
52 |
Correct |
189 ms |
20068 KB |
n=10000 |
53 |
Correct |
188 ms |
19176 KB |
n=6666 |
54 |
Correct |
183 ms |
18284 KB |
n=4000 |
55 |
Correct |
183 ms |
18028 KB |
n=2857 |
56 |
Correct |
174 ms |
17132 KB |
n=2000 |