# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516329 | 2022-01-21T06:17:59 Z | fcmalkcin | Gift (IZhO18_nicegift) | C++17 | 1010 ms | 524292 KB |
/*#pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops, no-stack-protector") #pragma GCC target("avx,avx2,fma")*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" #define F(i,a,b) for (ll i=a;i<=b;i++) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn=4e6+40; const ll mod=1000003 ; const ll base=317; /// you will be the best but now you just are trash /// goal 2/7 ll n, k; pll a[maxn]; vector<pll> gr[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("CHOCOLATE.inp", "r")) { freopen("CHOCOLATE.inp", "r", stdin); freopen("CHOCOLATE.out", "w", stdout); } ll n, k; cin>> n>> k; ll cnt=0; for (int i=1;i<=n;i++) { cin>> a[i].ff; cnt+=a[i].ff; a[i].ss=i; } sort(a+1,a+n+1); if (cnt%k!=0) { cout <<-1; return 0; } if (a[n].ff>(cnt/k)) { cout <<-1; return 0; } cnt/=k; pll pre=make_pair(0,0); ll dem=0; for (int i=1;i<=n;i++) { dem++; ll j=i; ll nw=a[i].ff+pre.ff; if(pre.ss) gr[dem].pb(pre); gr[dem].pb(a[i]); while (nw<cnt) { j++,nw+=a[j].ff; if (nw<=cnt) gr[dem].pb(a[j]); else gr[dem].pb(make_pair(a[j].ff-(nw-cnt),a[j].ss)); } assert(nw>=cnt); if (nw>cnt) { assert(a[j].ff>nw-cnt); pre=make_pair(nw-cnt,a[j].ss); } i=j; } assert(dem==k); /* for (int i=1;i<=k;i++) { for (auto to:gr[i]) cout <<to.ff<<" "<<to.ss<<" "; cout <<endl; }*/ vector<pair<ll,vector<ll>>> ans; while (1) { bool kt=true; ll val1=base; for (int i=1;i<=k;i++) { if (!gr[i].size()) { kt=false; break; } else { val1=min(val1,gr[i].back().ff); } } if (kt) { assert(val1); vector<ll> vt; for (int i=1;i<=k;i++) { if (gr[i].back().ff==val1) { vt.pb(gr[i].back().ss); gr[i].pop_back(); } else { gr[i][gr[i].size()-1].ff-=val1; vt.pb(gr[i].back().ss); } } ans.pb(make_pair(val1,vt)); } else { break; } } cout <<ans.size()<<endl; for (auto to:ans) { cout <<to.ff<<" "; for (auto p:to.ss) cout <<p<<" "; cout <<endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94204 KB | n=4 |
2 | Correct | 50 ms | 94236 KB | n=3 |
3 | Correct | 49 ms | 94164 KB | n=3 |
4 | Correct | 49 ms | 94196 KB | n=4 |
5 | Correct | 49 ms | 94160 KB | n=4 |
6 | Correct | 47 ms | 94148 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94204 KB | n=4 |
2 | Correct | 50 ms | 94236 KB | n=3 |
3 | Correct | 49 ms | 94164 KB | n=3 |
4 | Correct | 49 ms | 94196 KB | n=4 |
5 | Correct | 49 ms | 94160 KB | n=4 |
6 | Correct | 47 ms | 94148 KB | n=2 |
7 | Correct | 52 ms | 94240 KB | n=5 |
8 | Correct | 48 ms | 94200 KB | n=8 |
9 | Correct | 49 ms | 94204 KB | n=14 |
10 | Correct | 56 ms | 94248 KB | n=11 |
11 | Correct | 85 ms | 99648 KB | n=50000 |
12 | Correct | 73 ms | 99604 KB | n=50000 |
13 | Correct | 48 ms | 94140 KB | n=10 |
14 | Correct | 52 ms | 94228 KB | n=685 |
15 | Correct | 48 ms | 94276 KB | n=623 |
16 | Correct | 52 ms | 94320 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94204 KB | n=4 |
2 | Correct | 50 ms | 94236 KB | n=3 |
3 | Correct | 49 ms | 94164 KB | n=3 |
4 | Correct | 49 ms | 94196 KB | n=4 |
5 | Correct | 49 ms | 94160 KB | n=4 |
6 | Correct | 47 ms | 94148 KB | n=2 |
7 | Correct | 52 ms | 94240 KB | n=5 |
8 | Correct | 48 ms | 94200 KB | n=8 |
9 | Correct | 49 ms | 94204 KB | n=14 |
10 | Correct | 56 ms | 94248 KB | n=11 |
11 | Correct | 85 ms | 99648 KB | n=50000 |
12 | Correct | 73 ms | 99604 KB | n=50000 |
13 | Correct | 48 ms | 94140 KB | n=10 |
14 | Correct | 52 ms | 94228 KB | n=685 |
15 | Correct | 48 ms | 94276 KB | n=623 |
16 | Correct | 52 ms | 94320 KB | n=973 |
17 | Correct | 51 ms | 94296 KB | n=989 |
18 | Correct | 49 ms | 94364 KB | n=563 |
19 | Correct | 53 ms | 94364 KB | n=592 |
20 | Correct | 57 ms | 94392 KB | n=938 |
21 | Correct | 60 ms | 94292 KB | n=747 |
22 | Correct | 49 ms | 94336 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1010 ms | 524292 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94204 KB | n=4 |
2 | Correct | 50 ms | 94236 KB | n=3 |
3 | Correct | 49 ms | 94164 KB | n=3 |
4 | Correct | 49 ms | 94196 KB | n=4 |
5 | Correct | 49 ms | 94160 KB | n=4 |
6 | Correct | 47 ms | 94148 KB | n=2 |
7 | Correct | 52 ms | 94240 KB | n=5 |
8 | Correct | 48 ms | 94200 KB | n=8 |
9 | Correct | 49 ms | 94204 KB | n=14 |
10 | Correct | 56 ms | 94248 KB | n=11 |
11 | Correct | 85 ms | 99648 KB | n=50000 |
12 | Correct | 73 ms | 99604 KB | n=50000 |
13 | Correct | 48 ms | 94140 KB | n=10 |
14 | Correct | 52 ms | 94228 KB | n=685 |
15 | Correct | 48 ms | 94276 KB | n=623 |
16 | Correct | 52 ms | 94320 KB | n=973 |
17 | Correct | 51 ms | 94296 KB | n=989 |
18 | Correct | 49 ms | 94364 KB | n=563 |
19 | Correct | 53 ms | 94364 KB | n=592 |
20 | Correct | 57 ms | 94392 KB | n=938 |
21 | Correct | 60 ms | 94292 KB | n=747 |
22 | Correct | 49 ms | 94336 KB | n=991 |
23 | Runtime error | 1010 ms | 524292 KB | Execution killed with signal 9 |
24 | Halted | 0 ms | 0 KB | - |