Submission #379224

# Submission time Handle Problem Language Result Execution time Memory
379224 2021-03-17T14:23:31 Z jass921026 Gift (IZhO18_nicegift) C++14
0 / 100
571 ms 80856 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<vector<int> > idx;
vector<int> now, ch;
vector<pii> tmp;
int main(){ jizz
    int n, k;
    cin>>n>>k;
    ll sum=0, mxa=0;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        sum+=A[i];
        mxa=max(mxa,A[i]);
    }
    if(sum%k>0){
        cout<<"-1\n";
        return 0;
    }
    if(mxa>sum/k){
        cout<<"-1\n";
        return 0;
    }
    ll cur=0;
    for(int i=1;i<=n;i++){
        if(cur==0) now.pb(i);
        cur=cur+A[i];
        if(cur>sum/k){
            now.pb(i);
            cur-=sum/k;
        }
        tmp.pb(mkp(cur,now.size()-1));
    }
    sort(ALL(tmp));
    ll last=0;
    for(int i=0;i<n;i++){
        //cout<<"hi "<<tmp[i].F<<" "<<tmp[i].S<<"\n";
        ch.pb(tmp[i].S);
        if(tmp[i].F==last) continue;
        val.pb(tmp[i].F-last);
        idx.pb(now);
        for(auto j:ch){
            now[j]++;
        }
        last=tmp[i].F;
        ch.clear();
    }
    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];
        }
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     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 Incorrect 1 ms 364 KB Taken too much stones from the heap
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 Incorrect 1 ms 364 KB Taken too much stones from the heap
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 Incorrect 1 ms 364 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 571 ms 80856 KB Taken too much stones from the heap
2 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 Incorrect 1 ms 364 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -