답안 #486089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486089 2021-11-10T14:14:11 Z Ronin13 Gift (IZhO18_nicegift) C++14
0 / 100
1502 ms 524292 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define f first
#define s second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define inf 1e9+1
#define linf 1e18+1
using namespace std;

void solve(){
    int n;cin>>n;
    int k;cin>>k;
    ll a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum+=a[i];
    }
    vector<vector<pll> >vec(k+1);
    int ind=1;
    for(int i=1;i<=k;i++){
        ll left=sum/(ll)k;
        while(left>0){
            if(left>=a[ind])vec[i].pb({a[ind],ind}),left-=a[ind],ind++;
            else{
                a[ind]-=left,vec[i].pb({left,ind});
            }
        }
    }
    vector<int>idx(k+1,0);
    vector<vector<int> >ans;
    while(idx[1]<vec[1].size()){
        ll mn=inf;
        for(int i=1;i<=k;i++){
            int in=idx[i];
            mn=min(mn,vec[i][in].f);
        }
        vector<int>xx;
        xx.pb(mn);
        for(int i=1;i<=k;i++){
            xx.pb(vec[i][idx[i]].s);
        }
        ans.pb(xx);
        for(int i=1;i<=k;i++){
            int in=idx[i];
            vec[i][in].f-=mn;
            if(vec[i][in].f==0)idx[i]++;
        }
    }
    cout<<ans.size()<<"\n";
    for(int i=0;i<ans.size();i++){
        for(int to:ans[i])cout<<to<<" ";
        cout<<"\n";
    }

}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int test=1;//cin>>test;
    while(test--){
        solve();
        cout<<"\n";
    }
}

Compilation message

nicegift.cpp: In function 'void solve()':
nicegift.cpp:36:17: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while(idx[1]<vec[1].size()){
nicegift.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB n=4
2 Correct 1 ms 204 KB n=3
3 Incorrect 1 ms 976 KB Not all heaps are empty in the end
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB n=4
2 Correct 1 ms 204 KB n=3
3 Incorrect 1 ms 976 KB Not all heaps are empty in the end
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB n=4
2 Correct 1 ms 204 KB n=3
3 Incorrect 1 ms 976 KB Not all heaps are empty in the end
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1502 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB n=4
2 Correct 1 ms 204 KB n=3
3 Incorrect 1 ms 976 KB Not all heaps are empty in the end
4 Halted 0 ms 0 KB -