답안 #367418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367418 2021-02-17T08:51:46 Z nicolaalexandra Gift (IZhO18_nicegift) C++14
7 / 100
841 ms 71000 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 pas = 0, val = 0;
        w.clear();

        for (set <pair<int,int> > :: reverse_iterator it = s.rbegin(); it != s.rend(); it++){
            //sol[el].push_back(it->second);
            w.push_back(make_pair(it->first,it->second));
            val = it->first;
            pas++;
            if (pas == k)
                break;
        }

        sol[++el].push_back (val);

        for (auto it : w){
            int x = it.first, poz = it.second;
            sol[el].push_back(poz);
            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){
      |             ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23916 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23916 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 17 ms 23808 KB n=8
9 Incorrect 16 ms 23800 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23916 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 17 ms 23808 KB n=8
9 Incorrect 16 ms 23800 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 841 ms 71000 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 17 ms 23788 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23916 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 17 ms 23808 KB n=8
9 Incorrect 16 ms 23800 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -