답안 #334624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334624 2020-12-09T15:16:28 Z beksultan04 Gift (IZhO18_nicegift) C++14
100 / 100
829 ms 143672 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=1e18+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 > 0){
        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]-(q[i]-x));
                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 |= !v[0].empty();
            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:70: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]
   70 |             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 47468 KB n=4
2 Correct 32 ms 47340 KB n=3
3 Correct 32 ms 47340 KB n=3
4 Correct 32 ms 47360 KB n=4
5 Correct 32 ms 47340 KB n=4
6 Correct 32 ms 47340 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47468 KB n=4
2 Correct 32 ms 47340 KB n=3
3 Correct 32 ms 47340 KB n=3
4 Correct 32 ms 47360 KB n=4
5 Correct 32 ms 47340 KB n=4
6 Correct 32 ms 47340 KB n=2
7 Correct 33 ms 47340 KB n=5
8 Correct 32 ms 47340 KB n=8
9 Correct 32 ms 47340 KB n=14
10 Correct 32 ms 47340 KB n=11
11 Correct 62 ms 51040 KB n=50000
12 Correct 61 ms 50916 KB n=50000
13 Correct 32 ms 47340 KB n=10
14 Correct 33 ms 47340 KB n=685
15 Correct 32 ms 47340 KB n=623
16 Correct 34 ms 47340 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47468 KB n=4
2 Correct 32 ms 47340 KB n=3
3 Correct 32 ms 47340 KB n=3
4 Correct 32 ms 47360 KB n=4
5 Correct 32 ms 47340 KB n=4
6 Correct 32 ms 47340 KB n=2
7 Correct 33 ms 47340 KB n=5
8 Correct 32 ms 47340 KB n=8
9 Correct 32 ms 47340 KB n=14
10 Correct 32 ms 47340 KB n=11
11 Correct 62 ms 51040 KB n=50000
12 Correct 61 ms 50916 KB n=50000
13 Correct 32 ms 47340 KB n=10
14 Correct 33 ms 47340 KB n=685
15 Correct 32 ms 47340 KB n=623
16 Correct 34 ms 47340 KB n=973
17 Correct 34 ms 47340 KB n=989
18 Correct 37 ms 47468 KB n=563
19 Correct 35 ms 47468 KB n=592
20 Correct 34 ms 47468 KB n=938
21 Correct 35 ms 47468 KB n=747
22 Correct 34 ms 47488 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 527 ms 108856 KB n=1000000
2 Correct 322 ms 81476 KB n=666666
3 Correct 198 ms 66892 KB n=400000
4 Correct 485 ms 93896 KB n=285714
5 Correct 39 ms 48108 KB n=20000
6 Correct 441 ms 92644 KB n=181818
7 Correct 36 ms 47724 KB n=10000
8 Correct 82 ms 53612 KB n=6666
9 Correct 34 ms 47468 KB n=4000
10 Correct 322 ms 79724 KB n=2857
11 Correct 33 ms 47468 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47468 KB n=4
2 Correct 32 ms 47340 KB n=3
3 Correct 32 ms 47340 KB n=3
4 Correct 32 ms 47360 KB n=4
5 Correct 32 ms 47340 KB n=4
6 Correct 32 ms 47340 KB n=2
7 Correct 33 ms 47340 KB n=5
8 Correct 32 ms 47340 KB n=8
9 Correct 32 ms 47340 KB n=14
10 Correct 32 ms 47340 KB n=11
11 Correct 62 ms 51040 KB n=50000
12 Correct 61 ms 50916 KB n=50000
13 Correct 32 ms 47340 KB n=10
14 Correct 33 ms 47340 KB n=685
15 Correct 32 ms 47340 KB n=623
16 Correct 34 ms 47340 KB n=973
17 Correct 34 ms 47340 KB n=989
18 Correct 37 ms 47468 KB n=563
19 Correct 35 ms 47468 KB n=592
20 Correct 34 ms 47468 KB n=938
21 Correct 35 ms 47468 KB n=747
22 Correct 34 ms 47488 KB n=991
23 Correct 527 ms 108856 KB n=1000000
24 Correct 322 ms 81476 KB n=666666
25 Correct 198 ms 66892 KB n=400000
26 Correct 485 ms 93896 KB n=285714
27 Correct 39 ms 48108 KB n=20000
28 Correct 441 ms 92644 KB n=181818
29 Correct 36 ms 47724 KB n=10000
30 Correct 82 ms 53612 KB n=6666
31 Correct 34 ms 47468 KB n=4000
32 Correct 322 ms 79724 KB n=2857
33 Correct 33 ms 47468 KB n=2000
34 Correct 50 ms 49384 KB n=23514
35 Correct 49 ms 49384 KB n=23514
36 Correct 38 ms 47340 KB n=940
37 Correct 32 ms 47340 KB n=2
38 Correct 149 ms 60644 KB n=100000
39 Correct 151 ms 60644 KB n=100000
40 Correct 32 ms 47340 KB n=10
41 Correct 33 ms 47340 KB n=100
42 Correct 40 ms 47980 KB n=1000
43 Correct 755 ms 139444 KB n=1000000
44 Correct 829 ms 143672 KB n=1000000
45 Correct 652 ms 115780 KB n=666666
46 Correct 542 ms 105932 KB n=400000
47 Correct 314 ms 75244 KB n=2336
48 Correct 483 ms 93640 KB n=285714
49 Correct 444 ms 92900 KB n=181818
50 Correct 346 ms 80820 KB n=40000
51 Correct 354 ms 79236 KB n=20000
52 Correct 321 ms 77676 KB n=10000
53 Correct 330 ms 84204 KB n=6666
54 Correct 312 ms 73068 KB n=4000
55 Correct 319 ms 79596 KB n=2857
56 Correct 305 ms 71916 KB n=2000