답안 #334617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334617 2020-12-09T15:06:12 Z beksultan04 Gift (IZhO18_nicegift) C++14
0 / 100
247 ms 75220 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
vector <pii> v[N];
vector <int> ans[N];
int q[N];

main(){
    int n,k,i,j,sum=0,cnt=0,mx=0,aa=0;
    scan2(n,k)
    for (i=0;i<n;++i)
        scan1(q[i]);
    for (i=0;i<n;++i){
        mx = max(mx,q[i]);
        sum+=q[i];
    }
    if (mx*k > sum || sum%k){
        cout <<-1;
        ret 0;
    }
    else {
        int sz = sum/k,c=0;
        for (i=0;i<n;++i){
            if (c+q[i] >= sz){
                int x = c+q[i]-sz;
                v[cnt++].pb({q[i]-x,i+1});
                c = (q[i]+c)%sz;
                v[cnt].pb({c,i+1});
            }
            else {
                c+=q[i];
                v[cnt].pb({q[i],i+1});
            }
        }
        bool f=1;
        while (f){
            f=0;
            int mn = INF;
            for (i=0;i<k;++i){
                mn = min(mn,v[i].back().fr);
            }
            ans[aa].pb(mn);
            for (i=0;i<k;++i){
                pii x = v[i].back();
                v[i].pop_back();
                x.fr -= mn;
                ans[aa].pb(x.sc);
                if (x.fr > 0){
                    v[i].pb(x);
                    f=1;
                }
            }
            aa++;
        }
        cout <<aa<<"\n";
        for (i=0;i<aa;++i){
            for (j=0;j<ans[i].size();++j){
                cout <<ans[i][j]<<" ";
            }
            endi
        }
    }

}




Compilation message

nicegift.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main(){
      |      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:69:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for (j=0;j<ans[i].size();++j){
      |                      ~^~~~~~~~~~~~~~
nicegift.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:22:5: note: in expansion of macro 'scan2'
   22 |     scan2(n,k)
      |     ^~~~~
nicegift.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
nicegift.cpp:24:9: note: in expansion of macro 'scan1'
   24 |         scan1(q[i]);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47340 KB n=4
2 Correct 33 ms 47280 KB n=3
3 Correct 33 ms 47340 KB n=3
4 Incorrect 33 ms 47340 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47340 KB n=4
2 Correct 33 ms 47280 KB n=3
3 Correct 33 ms 47340 KB n=3
4 Incorrect 33 ms 47340 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47340 KB n=4
2 Correct 33 ms 47280 KB n=3
3 Correct 33 ms 47340 KB n=3
4 Incorrect 33 ms 47340 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 247 ms 75220 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47340 KB n=4
2 Correct 33 ms 47280 KB n=3
3 Correct 33 ms 47340 KB n=3
4 Incorrect 33 ms 47340 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -