Submission #651944

# Submission time Handle Problem Language Result Execution time Memory
651944 2022-10-20T16:29:58 Z vovik Gift (IZhO18_nicegift) C++17
49 / 100
2000 ms 253708 KB
//I wrote this code 4 u today
#include <bits/stdc++.h>
 
const int MAX_MEM = 5e8;
size_t mpos = 0;
char mem[MAX_MEM];
 
void *operator new(size_t n) {
    return (void *) (mem + (mpos += n) - n);
}
 
void operator delete(void *) noexcept {}
 
#define vc vector
 
#define nd node*
#define pnd pair<nd, nd>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vc<pll> vpll;
typedef vc<vll> vvll;
typedef vc<vpll> vvpll;
 
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
    ll operator()(const ll a, const ll b) {
        return (a * b) % MOD;
    }
};
 
 
template<typename T>
inline void sort(T &a) {
    sort(a.begin(), a.end());
}
 
template<typename T>
inline void unique(T &a) {
    a.resize(unique(a.begin(), a.end()) - a.begin());
}
 
template<typename T>
inline void reverse(T &a) {
    reverse(a.begin(), a.end());
}
 
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
 
#define int ll
 
int32_t main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vc<ll> a(n);
    ll sm = 0, mx = 0;
    for (auto &i : a) cin >> i, sm += i, mx = max(mx, i);
    if (sm % k || mx > sm / k) return cout << "-1\n", 0;
    set<pair<int, int>> alive;
    for (int i = 0; i < n; ++i) if (a[i]) alive.emplace(a[i], i);
    vc<vc<int>> ans;
    while (!alive.empty()) {
        vc<int> inds(k);
        for (int i = k - 1; i >= 0; --i) inds[i] = alive.rbegin()->second, alive.erase(prev(alive.end()));
        if (!a[inds.back()]) break;
        int d = min(sm / k - (alive.empty() ? 0 : alive.rbegin()->first), a[inds[0]]);
        ans.push_back({d});
        for (auto i : inds) ans.back().push_back(i + 1), a[i] -= d, alive.emplace(a[i], i);
        sm -= k * d;
    }
    cout << ans.size() << '\n';
    for (auto v : ans) {
        for (auto &i : v) cout << i << ' ';
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 30 ms 10576 KB n=50000
12 Correct 25 ms 9480 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 468 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 30 ms 10576 KB n=50000
12 Correct 25 ms 9480 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 468 KB n=973
17 Correct 1 ms 468 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 468 KB n=592
20 Correct 1 ms 468 KB n=938
21 Correct 1 ms 468 KB n=747
22 Correct 1 ms 468 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 789 ms 187524 KB n=1000000
2 Correct 506 ms 111904 KB n=666666
3 Correct 287 ms 66600 KB n=400000
4 Correct 205 ms 44400 KB n=285714
5 Correct 16 ms 3320 KB n=20000
6 Correct 134 ms 28804 KB n=181818
7 Correct 6 ms 1788 KB n=10000
8 Correct 5 ms 1544 KB n=6666
9 Correct 3 ms 852 KB n=4000
10 Correct 5 ms 2020 KB n=2857
11 Correct 2 ms 596 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 30 ms 10576 KB n=50000
12 Correct 25 ms 9480 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 468 KB n=973
17 Correct 1 ms 468 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 468 KB n=592
20 Correct 1 ms 468 KB n=938
21 Correct 1 ms 468 KB n=747
22 Correct 1 ms 468 KB n=991
23 Correct 789 ms 187524 KB n=1000000
24 Correct 506 ms 111904 KB n=666666
25 Correct 287 ms 66600 KB n=400000
26 Correct 205 ms 44400 KB n=285714
27 Correct 16 ms 3320 KB n=20000
28 Correct 134 ms 28804 KB n=181818
29 Correct 6 ms 1788 KB n=10000
30 Correct 5 ms 1544 KB n=6666
31 Correct 3 ms 852 KB n=4000
32 Correct 5 ms 2020 KB n=2857
33 Correct 2 ms 596 KB n=2000
34 Correct 25 ms 6312 KB n=23514
35 Correct 22 ms 6424 KB n=23514
36 Correct 1 ms 596 KB n=940
37 Correct 0 ms 212 KB n=2
38 Correct 82 ms 16712 KB n=100000
39 Correct 91 ms 16676 KB n=100000
40 Correct 0 ms 212 KB n=10
41 Correct 1 ms 340 KB n=100
42 Correct 4 ms 1364 KB n=1000
43 Correct 972 ms 253708 KB n=1000000
44 Execution timed out 2072 ms 159888 KB Time limit exceeded
45 Halted 0 ms 0 KB -