Submission #161770

# Submission time Handle Problem Language Result Execution time Memory
161770 2019-11-04T11:39:25 Z srvlt Gift (IZhO18_nicegift) C++14
7 / 100
1241 ms 71668 KB
#pragma GCC target ("avx2,sse2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
//#define endl "\n"

#define left fsdkfsdfsdfd
#define sum dfsdfsdfsdf
#define assign sdkfskdfkk

#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

int bit(signed x) {
    return __builtin_popcount(x);
}
int bit(ll x) {
    return __builtin_popcountll(x);
}

const int N = 1e6 + 7, M = 3e6;
int n, k, a[N], sum, mx, cnt;
ordered_set st;
vector <pii> todel;
vector <pair <int, vector <int> > > ans;

void decrease(int x) {
    vector <int> pos;
    auto it = st.find_by_order(n - k);
    while (it != st.end()) {
        todel.pb(*it);
        ++it;
    }
    for (auto i : todel) {
        st.erase(i);
        st.insert({i.fi - x, i.se});
        pos.pb(i.se);
        cnt++;
        if (cnt > M) {
            cout << -1;
            exit(0);
        }
    }
    todel = {};
    ans.pb({x, pos});
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
        mx = max(mx, a[i]);
        st.insert({a[i], i});
    }
    if (sum % k > 0 || mx > (sum + k - 1) / k) {
        cout << -1;
        return;
    }
    while (true) {
        int tmp = 0;
        if (n > k) {
            tmp = (*st.find_by_order(n - k - 1)).fi;
        }
        int val = sum / k - tmp;
        if (val == 0) {
            cout << -1;
            exit(0);
        }
        decrease(val);
        sum -= val * k;
        if (sum == 0) {
            break;
        }
    }
    cout << ans.size() << endl;
    for (auto i : ans) {
        cout << i.fi << " ";
        for (auto j : i.se) {
            cout << j << " ";
        }
        cout << endl;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}

Compilation message

nicegift.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("Ofast")
 
nicegift.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Incorrect 2 ms 376 KB Jury has the answer but participant has not
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Incorrect 2 ms 376 KB Jury has the answer but participant has not
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1241 ms 71668 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Incorrect 2 ms 376 KB Jury has the answer but participant has not
8 Halted 0 ms 0 KB -