답안 #153953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153953 2019-09-17T14:53:58 Z andrew Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 133828 KB
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl;exit(0);}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    ll n, k;
    cin >> n >> k;

    vector <ll> a(n);

    set <pll> st;

    ll sc = 0, mx = 0;

    for(int i = 0; i < n; i++){
        cin >> a[i];
        st.insert({a[i], i});
        sc += a[i];
        mx = max(mx, a[i]);
    }

    if(sc % k)vout(-1);

    pll fufel = *--st.end();
    st.erase(--st.end());
    sc -= mx;

    if(sc < mx)vout(-1);

    vector < pair<ll, pll> > ans;

    while(sc > mx){
        pll xe = *--st.end();
        st.erase(--st.end());
        if(st.empty())vout(-1);
        pll xx = *--st.end();
        st.erase(--st.end());
        xe.fi--;
        xx.fi--;
        ans.p_b({1ll, {xe.se, xx.se}});
        if(xe.fi)st.insert(xe);
        if(xx.fi)st.insert(xx);
        sc -= 2;
    }

    while(!st.empty()){
        pll xe = *--st.end();
        st.erase(--st.end());
        ans.p_b({xe.fi, {fufel.se, xe.se}});
    }

    cout << ans.size() << "\n";
    for(auto i : ans)cout << i.fi << " " << i.se.fi + 1 << " " << i.se.se + 1 << "\n";

    return 0;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 3 ms 504 KB n=14
10 Correct 3 ms 504 KB n=11
11 Correct 39 ms 5412 KB n=50000
12 Correct 43 ms 5996 KB n=50000
13 Correct 9 ms 1008 KB n=10
14 Correct 25 ms 2040 KB n=685
15 Correct 26 ms 2028 KB n=623
16 Correct 17 ms 1368 KB n=973
# 결과 실행 시간 메모리 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 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 3 ms 504 KB n=14
10 Correct 3 ms 504 KB n=11
11 Correct 39 ms 5412 KB n=50000
12 Correct 43 ms 5996 KB n=50000
13 Correct 9 ms 1008 KB n=10
14 Correct 25 ms 2040 KB n=685
15 Correct 26 ms 2028 KB n=623
16 Correct 17 ms 1368 KB n=973
17 Incorrect 29 ms 2152 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2029 ms 133828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 3 ms 504 KB n=14
10 Correct 3 ms 504 KB n=11
11 Correct 39 ms 5412 KB n=50000
12 Correct 43 ms 5996 KB n=50000
13 Correct 9 ms 1008 KB n=10
14 Correct 25 ms 2040 KB n=685
15 Correct 26 ms 2028 KB n=623
16 Correct 17 ms 1368 KB n=973
17 Incorrect 29 ms 2152 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -