답안 #93275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93275 2019-01-07T11:53:41 Z SamAnd Gift (IZhO18_nicegift) C++17
0 / 100
493 ms 63828 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
struct ban
{
    int i;
    long long x;
    ban(){}
    ban(int i, long long x)
    {
        this->i = i;
        this->x = x;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.x < b.x;
}

int n, k;
long long a[N];

void solv1()
{
    vector<vector<long long> > ans;
    priority_queue<ban> q;
    for (int i = 1; i <= n; ++i)
        q.push(ban(i, a[i]));
    bool z = false;
    while (1)
    {
        if (q.size() == 0)
        {
            z = true;
            break;
        }
        if (q.size() < k)
            break;
        vector<ban> v;
        for (int ii = 0; ii < k; ++ii)
        {
            v.push_back(q.top());
            q.pop();
        }
        long long minu = v[0].x;
        vector<long long> vv;
        vv.push_back(minu);
        for (int i = 0; i < k; ++i)
        {
            v[i].x -= minu;
            if (v[i].x)
                q.push(v[i]);
            vv.push_back(v[i].i);
        }
        ans.push_back(vv);
    }
    if (!z)
    {
        printf("-1\n");
        return;
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); ++i)
    {
        for (int j = 0; j < ans[i].size(); ++j)
            printf("%d ", ans[i][j]);
        printf("\n");
    }
}

int main()
{
    //freopen("input2.txt", "r", stdin);
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &a[i]);
    solv1();
    return 0;
}

Compilation message

nicegift.cpp: In function 'void solv1()':
nicegift.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (q.size() < k)
             ~~~~~~~~~^~~
nicegift.cpp:62:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<long long int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", ans.size());
                    ~~~~~~~~~~^
nicegift.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); ++i)
                     ~~^~~~~~~~~~~~
nicegift.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < ans[i].size(); ++j)
                         ~~^~~~~~~~~~~~~~~
nicegift.cpp:66:36: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' [-Wformat=]
             printf("%d ", ans[i][j]);
                                    ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:74: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:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Incorrect 2 ms 376 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Incorrect 2 ms 376 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Incorrect 2 ms 376 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 493 ms 63828 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Incorrect 2 ms 376 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -