Submission #84941

# Submission time Handle Problem Language Result Execution time Memory
84941 2018-11-17T19:45:14 Z ToadDaveski Gift (IZhO18_nicegift) C++11
100 / 100
882 ms 94084 KB
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
using namespace std;
vector <vector <pair <ll,ll> >  > q;
ll a[2000001];
map <ll,ll> poz;
vector <ll> ans;
int main()
{
    //ios_base::sync_with_stdio(0);
    ll n,k,i,j,ma=0;
    cin>>n>>k;
    ll sum=0,part;
    for(i=1;i<=n;i++)
    {
        scanf("%lld", a + i);
        sum+=a[i];
        ma=max(ma,a[i]);
    }
    part=sum/k;
    if (sum%k || part<ma )
    {
        cout<<-1;
        return 0;
    }
    sum=0;
    vector <pair <ll,ll> > temp;
    temp.clear();
    for(i=1;i<=n;i++)
    {
        sum+=a[i];
        if (sum>=part)
        {
            temp.push_back({a[i]-(sum-part),i});
            q.push_back(temp);
            temp.clear();
            sum=sum-part;
            if (sum) temp.push_back({sum,i});
        }
        else
        {
            temp.push_back({a[i],i});
        }
    }
    while(true)
    {
        ll mi=1e18;
        for(i=0;i<k;i++)
            mi=min(mi,q[i][poz[i]].fr);
        ans.push_back(mi);
        ll kol=0;
        for(i=0;i<k;i++)
        {
            ans.push_back(q[i][poz[i]].sc);
            q[i][poz[i]].fr-=mi;
            if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
            {
                poz[i]++;
                if (poz[i]<q[i].size()) kol++;
            }
        }
        if (!kol)
            break;
    }
    ll toad=0;
    printf("%d\n", ans.size() / (k + 1));
    while(toad<ans.size())
    {
        printf("%lld ", ans[toad]);
        if (((toad+1)%(k+1))==0)
            puts("");
        toad++;
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (poz[i]<q[i].size() && !q[i][poz[i]].fr)
nicegift.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (poz[i]<q[i].size()) kol++;
nicegift.cpp:68:40: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long unsigned int' [-Wformat=]
     printf("%d\n", ans.size() / (k + 1));
                    ~~~~~~~~~~~~~~~~~~~~^
nicegift.cpp:69:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(toad<ans.size())
           ~~~~^~~~~~~~~~~
nicegift.cpp:13:14: warning: unused variable 'j' [-Wunused-variable]
     ll n,k,i,j,ma=0;
              ^
nicegift.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", a + i);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 372 KB n=3
3 Correct 2 ms 372 KB n=3
4 Correct 2 ms 520 KB n=4
5 Correct 2 ms 672 KB n=4
6 Correct 2 ms 672 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 372 KB n=3
3 Correct 2 ms 372 KB n=3
4 Correct 2 ms 520 KB n=4
5 Correct 2 ms 672 KB n=4
6 Correct 2 ms 672 KB n=2
7 Correct 2 ms 672 KB n=5
8 Correct 2 ms 672 KB n=8
9 Correct 2 ms 672 KB n=14
10 Correct 2 ms 672 KB n=11
11 Correct 27 ms 4000 KB n=50000
12 Correct 31 ms 4000 KB n=50000
13 Correct 2 ms 4000 KB n=10
14 Correct 2 ms 4000 KB n=685
15 Correct 3 ms 4000 KB n=623
16 Correct 2 ms 4000 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 372 KB n=3
3 Correct 2 ms 372 KB n=3
4 Correct 2 ms 520 KB n=4
5 Correct 2 ms 672 KB n=4
6 Correct 2 ms 672 KB n=2
7 Correct 2 ms 672 KB n=5
8 Correct 2 ms 672 KB n=8
9 Correct 2 ms 672 KB n=14
10 Correct 2 ms 672 KB n=11
11 Correct 27 ms 4000 KB n=50000
12 Correct 31 ms 4000 KB n=50000
13 Correct 2 ms 4000 KB n=10
14 Correct 2 ms 4000 KB n=685
15 Correct 3 ms 4000 KB n=623
16 Correct 2 ms 4000 KB n=973
17 Correct 3 ms 4000 KB n=989
18 Correct 3 ms 4000 KB n=563
19 Correct 4 ms 4000 KB n=592
20 Correct 4 ms 4000 KB n=938
21 Correct 3 ms 4000 KB n=747
22 Correct 6 ms 4000 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 436 ms 57972 KB n=1000000
2 Correct 293 ms 57972 KB n=666666
3 Correct 162 ms 57972 KB n=400000
4 Correct 440 ms 57972 KB n=285714
5 Correct 15 ms 57972 KB n=20000
6 Correct 429 ms 57972 KB n=181818
7 Correct 11 ms 57972 KB n=10000
8 Correct 131 ms 57972 KB n=6666
9 Correct 5 ms 57972 KB n=4000
10 Correct 849 ms 57972 KB n=2857
11 Correct 5 ms 57972 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 372 KB n=3
3 Correct 2 ms 372 KB n=3
4 Correct 2 ms 520 KB n=4
5 Correct 2 ms 672 KB n=4
6 Correct 2 ms 672 KB n=2
7 Correct 2 ms 672 KB n=5
8 Correct 2 ms 672 KB n=8
9 Correct 2 ms 672 KB n=14
10 Correct 2 ms 672 KB n=11
11 Correct 27 ms 4000 KB n=50000
12 Correct 31 ms 4000 KB n=50000
13 Correct 2 ms 4000 KB n=10
14 Correct 2 ms 4000 KB n=685
15 Correct 3 ms 4000 KB n=623
16 Correct 2 ms 4000 KB n=973
17 Correct 3 ms 4000 KB n=989
18 Correct 3 ms 4000 KB n=563
19 Correct 4 ms 4000 KB n=592
20 Correct 4 ms 4000 KB n=938
21 Correct 3 ms 4000 KB n=747
22 Correct 6 ms 4000 KB n=991
23 Correct 436 ms 57972 KB n=1000000
24 Correct 293 ms 57972 KB n=666666
25 Correct 162 ms 57972 KB n=400000
26 Correct 440 ms 57972 KB n=285714
27 Correct 15 ms 57972 KB n=20000
28 Correct 429 ms 57972 KB n=181818
29 Correct 11 ms 57972 KB n=10000
30 Correct 131 ms 57972 KB n=6666
31 Correct 5 ms 57972 KB n=4000
32 Correct 849 ms 57972 KB n=2857
33 Correct 5 ms 57972 KB n=2000
34 Correct 16 ms 57972 KB n=23514
35 Correct 16 ms 57972 KB n=23514
36 Correct 2 ms 57972 KB n=940
37 Correct 2 ms 57972 KB n=2
38 Correct 126 ms 57972 KB n=100000
39 Correct 108 ms 57972 KB n=100000
40 Correct 3 ms 57972 KB n=10
41 Correct 3 ms 57972 KB n=100
42 Correct 11 ms 57972 KB n=1000
43 Correct 663 ms 79940 KB n=1000000
44 Correct 824 ms 94084 KB n=1000000
45 Correct 610 ms 94084 KB n=666666
46 Correct 522 ms 94084 KB n=400000
47 Correct 882 ms 94084 KB n=2336
48 Correct 464 ms 94084 KB n=285714
49 Correct 418 ms 94084 KB n=181818
50 Correct 357 ms 94084 KB n=40000
51 Correct 413 ms 94084 KB n=20000
52 Correct 686 ms 94084 KB n=10000
53 Correct 791 ms 94084 KB n=6666
54 Correct 828 ms 94084 KB n=4000
55 Correct 849 ms 94084 KB n=2857
56 Correct 842 ms 94084 KB n=2000