답안 #378596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378596 2021-03-17T02:07:23 Z abc864197532 Gift (IZhO18_nicegift) C++17
0 / 100
13 ms 364 KB
#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();
    }
}

Compilation message

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) {
      |                ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 364 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -