Submission #496653

#TimeUsernameProblemLanguageResultExecution timeMemory
496653ergaganGift (IZhO18_nicegift)C++17
100 / 100
969 ms107168 KiB
//я так много думал, что опять попал #include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define f first #define s second #define left(v) v + v #define right(v) v + v + 1 #define ub upper_bound #define lb lower_bound using namespace std; typedef long long ll; //17 SEVENTEEN const long double Pi = acos(-1.0); const ll dx[] = {0,0,1,-1}; const ll dy[] = {1,-1,0,0}; const ll N = (ll) 1e6 + 17; const ll M = (ll) 5e3 + 69; const ll inf = (ll) 1e14 + 3; const ll mod = (ll) 1e9 + 7; ll sq(ll x) { return x * x; } ll zxc = 1, a[N]; vector<ll> pos; vector<pair<ll, ll> > v; vector<vector<ll> > ans; bool check() { for(auto x : v) if(x.f) return 1; return 0; } void solve() { ll n, k, mx = 0, sum = 0; cin >> n >> k; for(ll i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); sum += a[i]; } if(sum % k) { cout << "-1\n"; return; } sum /= k; if(mx > sum) { cout << "-1\n"; return; } ll cur = 0; pos.pb(0); for(ll i = 1; i <= n; i++) { if(cur + a[i] > sum) v.pb({sum - cur, i}), a[i] = a[i] - sum + cur, pos.pb(v.size()), i--, cur = 0; else { v.pb({a[i], i}), cur += a[i]; if(cur == sum && i != n) pos.pb(v.size()), cur = 0; } } sum *= k; while(sum) { vector<ll> cur; ll mn = inf; for(ll p : pos) mn = min(mn, v[p].f); cur.pb(mn); for(ll p : pos) cur.pb(v[p].s); ans.pb(cur); for(ll i = 0; i < pos.size(); i++) { v[pos[i]].f -= mn; sum -= mn; if(!v[pos[i]].f) pos[i]++; } } cout << ans.size() << "\n"; for(auto x : ans) { for(ll val : x) cout << val << " "; cout << "\n"; } } int main(/*Уверенно*/) { //ios_base::sync_with_stdio(0); // cin.tie(0); /* freopen(".in", "r", stdin); freopen(".out", "w", stdout); */ // cin >> zxc; while(zxc--) { solve(); } return 0; } // さよならさ いかなくちゃ

Compilation message (stderr)

nicegift.cpp: In function 'void solve()':
nicegift.cpp:86:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for(ll i = 0; i < pos.size(); i++) {
      |                       ~~^~~~~~~~~~~~
#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...