Submission #367408

# Submission time Handle Problem Language Result Execution time Memory
367408 2021-02-17T08:19:39 Z nicolaalexandra Gift (IZhO18_nicegift) C++14
0 / 100
551 ms 70956 KB
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;

set <pair<int,int> > s;
vector <pair<int,int> > w;
vector <int> sol[DIM];
int v[DIM];
int n,k,i,el;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>k;
    for (i=1;i<=n;i++){
        cin>>v[i];
        s.insert(make_pair(v[i],i));
    }

    while (!s.empty()){
        if (s.size() < k){
            cout<<-1;
            return 0;
        }

        int val = s.begin()->first;
        sol[++el].push_back (val);

        int pas = 0;
        w.clear();
        for (auto it : s){
            w.push_back(it);
            sol[el].push_back(it.second);

            pas++;
            if (pas == k)
                break;
        }

        for (auto it : w){
            int x = it.first, poz = it.second;
            s.erase(make_pair(x,poz));
            if (x > val)
                s.insert(make_pair(x-val,poz));
        }
    }

    cout<<el<<"\n";
    for (i=1;i<=el;i++){
        for (auto it : sol[i])
            cout<<it<<" ";
        cout<<"\n";
    }


    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:23:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         if (s.size() < k){
      |             ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB n=4
2 Incorrect 14 ms 23788 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB n=4
2 Incorrect 14 ms 23788 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB n=4
2 Incorrect 14 ms 23788 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 551 ms 70956 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB n=4
2 Incorrect 14 ms 23788 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -