제출 #173909

#제출 시각아이디문제언어결과실행 시간메모리
173909VEGAnnGift (IZhO18_nicegift)C++14
49 / 100
416 ms49600 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define pii pair<int, int> #define pli pair<ll, 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 = 1000100; set<pli, greater<pli> > st; vector<vector<ll> > ans; vector<ll> vc; int n, k; 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]); } if (ok){ 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 (ll x : ans[it]) cout << " " << x + 1; cout << '\n'; } } else { cout << -1; } return 0; } for (int i = 0; i < n; i++){ st.insert(MP(a[i], i)); } for (ll po = 59; po >= 0; po--){ ll cur = (1ll << po); while ((*st.begin()).ft > 0){ vc.clear(); vc.PB(cur); bool was = 0; for (int it = 0; it < k; it++){ pli cr = (*st.begin()); st.erase(st.begin()); if (cr.ft < cur) { vc.PB(cr.sd); was = 1; break; } a[cr.sd] -= cur; vc.PB(cr.sd); } if (was) { for (int it = 1; it < sz(vc); it++){ int x = vc[it]; if (it < sz(vc) - 1) a[x] += cur; st.insert(MP(a[x], x)); } break; } else { ans.PB(vc); for (int it = 1; it < sz(vc); it++){ int x = vc[it]; st.insert(MP(a[x], x)); } } } } if ((*st.begin()).ft > 0) BAD(); cout << sz(ans) << '\n'; for (int it = 0; it < sz(ans); it++){ // cout << "1"; for (int i = 0; i < sz(ans[it]); i++){ if (i == 0) cout << ans[it][0]; else cout << " " << ans[it][i] + 1; } cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...