답안 #378730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378730 2021-03-17T03:35:53 Z jass921026 Gift (IZhO18_nicegift) C++14
30 / 100
1234 ms 141660 KB
// This is fake solution qq
#include<bits/stdc++.h>
using namespace std;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef pair<ll,int> pii;
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mkp make_pair
const int MAXN=1E6+10, MAX_OPS=3E6;
ll A[MAXN];
vector<ll> val;
vector<ll> tmp, tmp2;
vector<vector<ll> > idx;
priority_queue<pii> pq;
int main(){ jizz
    int n, k;
    cin>>n>>k;
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        sum+=A[i];
        pq.push(mkp(A[i],i));
    }
    if(sum%k>0){
        cout<<"-1\n";
        return 0;
    }
    bool ok=true;
    for(int i=0;i*k<MAX_OPS;i++){
        tmp.clear();
        tmp2.clear();
        if(pq.size()<k){
            ok=false;
            break;
        }
        for(int j=0;j<k;j++){
            pii cur=pq.top();
            tmp.pb(cur.F);
            tmp2.pb(cur.S);
            pq.pop();
        }
        val.pb(1);
        idx.pb(tmp2);
        for(int j=0;j<k;j++){
            tmp[j]-=1;
            if(tmp[j]) pq.push(mkp(tmp[j],tmp2[j]));
        }
        if(pq.size()==0) break;
    }
    if(val.size()*k>MAX_OPS) ok=false;
    if(ok){
        cout<<val.size()<<"\n";
        for(int i=0;i<val.size();i++){
            cout<<val[i]<<" ";
            for(int j=0;j<k;j++){
                cout<<idx[i][j]<<" \n"[j==k-1];
            }
        }
    } else{
        cout<<"-1\n";
        return 0;
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:35:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if(pq.size()<k){
      |            ~~~~~~~~~^~
nicegift.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int i=0;i<val.size();i++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 7 ms 1320 KB n=14
10 Correct 6 ms 1132 KB n=11
11 Correct 50 ms 5348 KB n=50000
12 Correct 40 ms 5428 KB n=50000
13 Correct 23 ms 3868 KB n=10
14 Correct 25 ms 3352 KB n=685
15 Correct 28 ms 3736 KB n=623
16 Correct 21 ms 2208 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 7 ms 1320 KB n=14
10 Correct 6 ms 1132 KB n=11
11 Correct 50 ms 5348 KB n=50000
12 Correct 40 ms 5428 KB n=50000
13 Correct 23 ms 3868 KB n=10
14 Correct 25 ms 3352 KB n=685
15 Correct 28 ms 3736 KB n=623
16 Correct 21 ms 2208 KB n=973
17 Correct 26 ms 2848 KB n=989
18 Correct 14 ms 1260 KB n=563
19 Correct 20 ms 1772 KB n=592
20 Correct 20 ms 1772 KB n=938
21 Correct 15 ms 1536 KB n=747
22 Correct 19 ms 1516 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1234 ms 141660 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 7 ms 1320 KB n=14
10 Correct 6 ms 1132 KB n=11
11 Correct 50 ms 5348 KB n=50000
12 Correct 40 ms 5428 KB n=50000
13 Correct 23 ms 3868 KB n=10
14 Correct 25 ms 3352 KB n=685
15 Correct 28 ms 3736 KB n=623
16 Correct 21 ms 2208 KB n=973
17 Correct 26 ms 2848 KB n=989
18 Correct 14 ms 1260 KB n=563
19 Correct 20 ms 1772 KB n=592
20 Correct 20 ms 1772 KB n=938
21 Correct 15 ms 1536 KB n=747
22 Correct 19 ms 1516 KB n=991
23 Incorrect 1234 ms 141660 KB Not all heaps are empty in the end
24 Halted 0 ms 0 KB -