Submission #378708

# Submission time Handle Problem Language Result Execution time Memory
378708 2021-03-17T03:27:19 Z jass921026 Gift (IZhO18_nicegift) C++14
7 / 100
542 ms 70140 KB
#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(tmp[k-1]);
        idx.pb(tmp2);
        for(int j=0;j<k;j++){
            tmp[j]-=tmp[k-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:34: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]
   34 |         if(pq.size()<k){
      |            ~~~~~~~~~^~
nicegift.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i=0;i<val.size();i++){
      |                     ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 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 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 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 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 542 ms 70140 KB n=1000000
2 Correct 334 ms 38972 KB n=666666
3 Correct 238 ms 21184 KB n=400000
4 Incorrect 91 ms 11392 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 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 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -