답안 #161780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161780 2019-11-04T12:01:54 Z srvlt Gift (IZhO18_nicegift) C++14
30 / 100
2000 ms 96276 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 <ll, int>, null_type, less <pair <ll, 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 <ll, 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, cnt;
ll sum, mx, a[N];
ordered_set st;
vector <pii> todel;
vector <pair <ll, vector <int> > > ans;

void decrease(ll 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) {
        ll tmp = 0;
        if (n > k) {
            tmp = (*st.find_by_order(n - k - 1)).fi;
        }
        ll last = (*st.find_by_order(n - k)).fi;
        ll val = min(last, 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")
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 1 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 1 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 380 KB n=11
11 Correct 97 ms 6376 KB n=50000
12 Correct 85 ms 5996 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 3 ms 552 KB n=623
16 Correct 3 ms 504 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 1 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 380 KB n=11
11 Correct 97 ms 6376 KB n=50000
12 Correct 85 ms 5996 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 3 ms 552 KB n=623
16 Correct 3 ms 504 KB n=973
17 Correct 3 ms 504 KB n=989
18 Correct 3 ms 376 KB n=563
19 Correct 3 ms 376 KB n=592
20 Correct 3 ms 376 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 504 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 96276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 1 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 380 KB n=11
11 Correct 97 ms 6376 KB n=50000
12 Correct 85 ms 5996 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 3 ms 552 KB n=623
16 Correct 3 ms 504 KB n=973
17 Correct 3 ms 504 KB n=989
18 Correct 3 ms 376 KB n=563
19 Correct 3 ms 376 KB n=592
20 Correct 3 ms 376 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 504 KB n=991
23 Execution timed out 2065 ms 96276 KB Time limit exceeded
24 Halted 0 ms 0 KB -