제출 #645688

#제출 시각아이디문제언어결과실행 시간메모리
645688mentaldoraGift (IZhO18_nicegift)C++14
30 / 100
35 ms7020 KiB
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz size()
#define mk make_pair
#define ff first
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define ss second
#define all(x) x.begin(), x.end()
#define Resh cin>>tt;while(tt--)solve();
#define yes cout <<"Yes"<<"\n";
#define no cout <<"No"<<"\n";
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define left(v) v + v
#define right(v) v + v + 1
const long double PI = acos(-1);
const long long n6 = 1e6 + 10;
const long long n5 = 1e5+1;
const long long n4 = 1e4 + 10;
const long long inf = 1e9;
const long long mod = 16714589;
const int BL = 60090;
const long long MAXN = 1e5+5;

ll a[n5];
multiset<pll> ms;
vector<vector<pll>> ans;
main() {
    fast
    ll n, k, cnt=0;
    cin >> n >> k;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
        cnt+=a[i];
    }
    if(cnt % k) {
        cout << -1;
        return 0;
    }
    for(int i = 1;i <= n;i++) {
        ms.insert(mk(a[i], i));
    }
    pll p2 = *ms.rbegin();
    if(p2.ff > cnt/k) {
        cout << -1;
        return 0;
    }
    while(ms.sz >= k) {
        vector<pll> v;
        while(v.sz < k) {
            pll p = *ms.rbegin();
            p.ff--;
            v.pb(p);
            ms.erase(--ms.end());
        }
        for(auto c : v) {
            if(c.ff) {
                ms.insert(c);
            }
        }
        ans.pb(v);
    }
    cout << ans.size() <<'\n';
    for(auto c : ans) {
        cout << "1 ";
        for(auto t : c) {
            cout << t.ss << " ";
        }
        cout <<'\n';
    }
}

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

nicegift.cpp:1: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    1 | #pragma comment(linker, "/stack:200000000")
      | 
nicegift.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main() {
      | ^~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:54:17: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   54 |     while(ms.sz >= k) {
      |           ~~~~~~^~~~
nicegift.cpp:56:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   56 |         while(v.sz < 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...