# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511100 | 2022-01-15T06:04:26 Z | Mazaalai | Gift (IZhO18_nicegift) | C++17 | 3 ms | 588 KB |
#include <bits/stdc++.h> #define pb push_back #define ff first #define ss second #define LLA(x) x.rbegin(),x.rend() #define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n"; #define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n'; using namespace std; using ll = long long; using PII = pair <ll, ll>; ll n, k, onePick = 1; bool impossible; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> n >> k; vector <vector <ll> > ans; set <PII> bfs; ll sum = 0; vector <ll> vals, vals1; for (int i = 1; i <= n; i++) { ll x; cin >> x; sum += x; vals.pb(x); bfs.insert({x, i}); } sort(LLA(vals)); if (sum % k != 0) { cout << "-1\n"; return 0; } if (vals[0] == vals.back()) { ll cycleLen = k * n / gcd(k, n); // 4, 6, 2-> 12 ll oneCycleContribution = cycleLen / n; // onePick = vals[0] / oneCycleContribution; for (auto& el : vals) el /= onePick; sum /= onePick; } while(!impossible && sum > 0) { vector <ll> pick(1, onePick); vector <PII> add; for (int i = 0; i < k; i++) { auto it = --bfs.end(); PII cur = *it; bfs.erase(it); pick.pb(cur.ss); cur.ff--; sum--; if (cur.ff < 0) { impossible = 1; break; } add.pb(cur); } ans.pb(pick); for (auto el : add) bfs.insert(el); } // int dbg = 0; if (impossible) { cout << "-1\n"; return 0; } cout << ans.size() << '\n'; for (auto el : ans) { print(el); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 588 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |