답안 #844085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844085 2023-09-05T07:42:02 Z Darren0724 Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 227724 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define x first
#define y second
const int INF=1e18;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,k;cin>>n>>k;
    set<pair<int,int>> m;
    int total=0;
    for(int i=0;i<n;i++){
        int p;cin>>p;
        total+=p;
        m.insert({p,i+1});
    }
    if(total%k!=0){
        cout<<-1<<endl;
        return 0;
    }
    vector<vector<int>> ans;
    while(m.size()>k+1){
        pair<int,int> d=*m.begin();
        int mn=d.x;
        m.erase(m.begin());
        vector<pair<int,int>> v;
        v.push_back(d);
        for(int i=0;i<k-1;i++){
            v.push_back(*m.rbegin());
            m.erase(--m.end());
            mn=min(mn,v.back().first-1);
        }
        mn=1;
        vector<int> idx(k);
        for(int i=0;i<k;i++){
            idx[i]=v[i].y;
            v[i].x-=mn;
        }
        idx.push_back(mn);
        reverse(idx.begin(),idx.end());
        ans.push_back(idx);
        for(int i=0;i<k;i++){
            if(v[i].x>0){
                m.insert(v[i]);
            }
        }
    }
    total=0;
    for(auto p:m){
        total+=p.x;
    }
    int need=total/k;
    vector<pair<int,int>> tmp(m.begin(),m.end());
    int sz=tmp.size();
    for(int i=0;i<sz;i++){
        int d=need-tmp[i].x;
        if(d<0){
            cout<<-1<<endl;
            return 0;
        }
        if(d==0){
            continue;
        }
        vector<int> idx;
        for(int j=0;j<sz;j++){
            if(i==j)continue;
            idx.push_back(tmp[j].second);
        }
        idx.push_back(d);
        reverse(idx.begin(),idx.end());
        ans.push_back(idx);
    }
    cout<<ans.size()<<endl;
    for(auto &v:ans){
        for(auto &j:v){
            cout<<j<<' ';
        }
        cout<<endl;
    }
    
    return 0;
}

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:23:19: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     while(m.size()>k+1){
      |           ~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 8 ms 868 KB n=14
10 Correct 2 ms 348 KB n=11
11 Correct 82 ms 5436 KB n=50000
12 Correct 85 ms 5380 KB n=50000
13 Correct 21 ms 1172 KB n=10
14 Correct 63 ms 3080 KB n=685
15 Correct 69 ms 3332 KB n=623
16 Correct 41 ms 2064 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 8 ms 868 KB n=14
10 Correct 2 ms 348 KB n=11
11 Correct 82 ms 5436 KB n=50000
12 Correct 85 ms 5380 KB n=50000
13 Correct 21 ms 1172 KB n=10
14 Correct 63 ms 3080 KB n=685
15 Correct 69 ms 3332 KB n=623
16 Correct 41 ms 2064 KB n=973
17 Incorrect 57 ms 3132 KB Not all heaps are empty in the end
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2043 ms 227724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 8 ms 868 KB n=14
10 Correct 2 ms 348 KB n=11
11 Correct 82 ms 5436 KB n=50000
12 Correct 85 ms 5380 KB n=50000
13 Correct 21 ms 1172 KB n=10
14 Correct 63 ms 3080 KB n=685
15 Correct 69 ms 3332 KB n=623
16 Correct 41 ms 2064 KB n=973
17 Incorrect 57 ms 3132 KB Not all heaps are empty in the end
18 Halted 0 ms 0 KB -