제출 #378596

#제출 시각아이디문제언어결과실행 시간메모리
378596abc864197532Gift (IZhO18_nicegift)C++17
0 / 100
13 ms364 KiB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
    for (auto a : x) cout << x << ' ';\
    cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 2000000;

int a[N], n, k;

struct op {
    vector <int> ans;
    int v;
};

void solve_same() {
    
}

void solve_count() {
    if (accumulate(a, a + n, 0ll) % k != 0) {
        cout << -1 << endl;
        return;
    }
    set <int> p;
    vector <op> ans;
    for (int i = 0; i < n; ++i) {
        if (a[i] && p.size() < k) {
            p.insert(i);
        }
        while (p.size() == k) {
            vector <int> tmp;
            for (int i : p) tmp.pb(i);
            ans.pb({tmp, 1});
            for (int i : tmp) {
                a[i]--;
                if (!a[i]) p.erase(i);
            }
        }
    }
    cout << ans.size() << endl;
    for (op i : ans) {
        cout << i.v << ' ';
        for (int j : i.ans) cout << j << ' ';
        cout << endl;
    }
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    if (*max_element(a, a + n) == *min_element(a, a + n)) {
        solve_same();
    } else {
        solve_count();
    }
}

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

nicegift.cpp: In function 'void solve_count()':
nicegift.cpp:39:30: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         if (a[i] && p.size() < k) {
      |                     ~~~~~~~~~^~~
nicegift.cpp:42:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |         while (p.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...