제출 #378652

#제출 시각아이디문제언어결과실행 시간메모리
378652wiwihoGift (IZhO18_nicegift)C++14
30 / 100
2084 ms257548 KiB
#include <bits/stdc++.h>

#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;

using pll = pair<ll, ll>;
using pii = pair<int, int>;

const ll MAX = 1LL << 60;

ostream& operator<<(ostream& o, pll p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll iceil(ll a, ll b){
    return (a + b - 1) / b;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    priority_queue<pll> pq;

    for(int i = 1; i <= n; i++){
        ll a;
        cin >> a;
        pq.push(mp(a, i));
    }

    vector<pair<ll, vector<int>>> ans;
    while(pq.size() >= k){
        vector<pll> t;
        for(int i = 0; i < k; i++){
            t.eb(pq.top());
            pq.pop();
        }
        ll tmp = 1;
        ans.eb(mp(tmp, vector<int>()));
        for(pll i : t){
            ans.back().S.eb(i.S);
            i.F -= tmp;
            if(i.F) pq.push(i);
        }
    }

    if(!pq.empty()){
        cout << "-1\n";
        return 0;
    }

    cout << ans.size() << "\n";
    for(auto& i : ans){
        cout << i.F << " ";
        printv(i.S, cout);
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp: In function 'int main()':
nicegift.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |     while(pq.size() >= k){
      |           ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...