답안 #93281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93281 2019-01-07T11:59:27 Z SamAnd Gift (IZhO18_nicegift) C++17
7 / 100
487 ms 65328 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;
        for (int i = 1; i < k; ++i)
            minu = min(minu, v[i].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("%lld ", 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:64: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:65:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); ++i)
                     ~~^~~~~~~~~~~~
nicegift.cpp:67:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < ans[i].size(); ++j)
                         ~~^~~~~~~~~~~~~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:76: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:78: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 Correct 2 ms 252 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 296 KB n=4
6 Correct 2 ms 376 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 296 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Incorrect 2 ms 376 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 296 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Incorrect 2 ms 376 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 487 ms 65328 KB n=1000000
2 Correct 296 ms 40736 KB n=666666
3 Correct 172 ms 23504 KB n=400000
4 Incorrect 82 ms 13684 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 252 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 296 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Incorrect 2 ms 376 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -