Submission #92787

# Submission time Handle Problem Language Result Execution time Memory
92787 2019-01-04T14:23:32 Z Vardanyan Gift (IZhO18_nicegift) C++14
30 / 100
1367 ms 118932 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 1000*1000+5;
pair<long long,int> a[N];

int main()   {
    int n,k;
    scanf("%d%d",&n,&k);
    long long sum = 0;
   long long mns = 1;
    set<pair<long long,int >,greater<pair<long long,int> > > ms;
    for(int i = 1;i<=n;i++){
            scanf("%lld",&a[i].first);
            a[i].second = i;
            sum+=a[i].first;
            ms.insert(a[i]);
    }
    sort(a+1,a+1+n);
    if(sum>1000*100){
        long long x = k/__gcd(n,k);
        if(a[n].first%x){
            printf("-1\n");
            return 0;
        }
        mns = a[n].first/x;
    }
    vector<vector<int> > ans;
    while(1){
        int kk = k;
        vector<int> now;
        set<pair<long long,int> >::iterator it = ms.begin();
        vector<pair<long long,int> > add;
        for(;it!=ms.end();it++){
            pair<long long,int> x = *it;
            if(x.first-mns<0){
                printf("-1\n");
                return 0;
            }
            //x.first--;
            sum-=mns;
            now.push_back(x.second);
            kk--;
            add.push_back(x);
            if(kk == 0) break;
        }
        for(int i = 0;i<add.size();i++){
                ms.erase(ms.find(add[i]));
                add[i].first-=mns;
                ms.insert(add[i]);
        }
        ans.push_back(now);
        if(sum == 0) break;
    }
    printf("%d\n",ans.size());
    for(int i = 0;i<ans.size();i++){
        printf("%d ",mns);
        for(int j = 0;j<ans[i].size();j++){
            printf("%lld ",ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:47:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<add.size();i++){
                       ~^~~~~~~~~~~
nicegift.cpp:55:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
nicegift.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<ans.size();i++){
                   ~^~~~~~~~~~~
nicegift.cpp:57:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         printf("%d ",mns);
                         ^
nicegift.cpp:58:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0;j<ans[i].size();j++){
                       ~^~~~~~~~~~~~~~
nicegift.cpp:59:37: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' [-Wformat=]
             printf("%lld ",ans[i][j]);
                                     ^
nicegift.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
nicegift.cpp:14:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[i].first);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 252 KB n=3
4 Correct 2 ms 248 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 252 KB n=3
4 Correct 2 ms 248 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 1016 KB n=8
9 Correct 10 ms 1204 KB n=14
10 Correct 7 ms 1016 KB n=11
11 Correct 80 ms 8112 KB n=50000
12 Correct 83 ms 7820 KB n=50000
13 Correct 34 ms 3496 KB n=10
14 Correct 32 ms 3112 KB n=685
15 Correct 37 ms 3368 KB n=623
16 Correct 21 ms 2096 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 252 KB n=3
4 Correct 2 ms 248 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 1016 KB n=8
9 Correct 10 ms 1204 KB n=14
10 Correct 7 ms 1016 KB n=11
11 Correct 80 ms 8112 KB n=50000
12 Correct 83 ms 7820 KB n=50000
13 Correct 34 ms 3496 KB n=10
14 Correct 32 ms 3112 KB n=685
15 Correct 37 ms 3368 KB n=623
16 Correct 21 ms 2096 KB n=973
17 Correct 37 ms 2720 KB n=989
18 Correct 16 ms 1016 KB n=563
19 Correct 25 ms 1400 KB n=592
20 Correct 26 ms 1400 KB n=938
21 Correct 21 ms 1144 KB n=747
22 Correct 22 ms 1272 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 1367 ms 118932 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 252 KB n=3
4 Correct 2 ms 248 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 1016 KB n=8
9 Correct 10 ms 1204 KB n=14
10 Correct 7 ms 1016 KB n=11
11 Correct 80 ms 8112 KB n=50000
12 Correct 83 ms 7820 KB n=50000
13 Correct 34 ms 3496 KB n=10
14 Correct 32 ms 3112 KB n=685
15 Correct 37 ms 3368 KB n=623
16 Correct 21 ms 2096 KB n=973
17 Correct 37 ms 2720 KB n=989
18 Correct 16 ms 1016 KB n=563
19 Correct 25 ms 1400 KB n=592
20 Correct 26 ms 1400 KB n=938
21 Correct 21 ms 1144 KB n=747
22 Correct 22 ms 1272 KB n=991
23 Incorrect 1367 ms 118932 KB Added number should be positive
24 Halted 0 ms 0 KB -