Submission #89501

# Submission time Handle Problem Language Result Execution time Memory
89501 2018-12-15T06:58:10 Z Hideo Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 134480 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1e6 + 7;
const int INF = 1e9 + 7;

int a[N], p[N];
int n, k, s;

vector < pair < int, int > > dq[N];
vector < int > ans[N];

main(){
	cin >> n >> k;
	int mx = -1;
	for (int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
        mx = max(mx, a[i]);
	}
	int h = s / k, cs = 0, c = 0;
	if (mx > h || s % k != 0){
        cout << -1;
        return 0;
	}
	for (int i = 0; i < n; i++){
        if(a[i] == 0) continue;
        if (cs + a[i] >= h){
            a[i] -= (h - cs);
            dq[c].push_back(make_pair(h - cs, i));
            cs = 0; i--; c++;
            continue;
        }
        cs += a[i];
        dq[c].push_back(make_pair(a[i], i));
	}
	int g = 0;
	while (s != 0){
        int mn = -1;
        for (int i = 0; i < k; i++){
            if (mn == -1){
                mn = dq[i][p[i]].first;
                continue;
            }
            mn = min(mn, dq[i][p[i]].first);
        }
        ans[g].push_back(mn);
        for (int i = 0; i < k; i++){
            dq[i][p[i]].first -= mn;
            ans[g].push_back(dq[i][p[i]].second + 1);
            if(dq[i][p[i]].first == 0)
                p[i]++;
        }
        g++;
        s -= (mn * k);
	}
	cout << g << endl;
	int it = 0;
	while (it != g){
        for (int i = 0; i < ans[it].size(); i++){
            cout << ans[it][i] << " ";
        }
        cout << endl;
        it++;
	}
}

Compilation message

nicegift.cpp:14:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < ans[it].size(); i++){
                         ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47352 KB n=4
2 Correct 49 ms 47452 KB n=3
3 Correct 49 ms 47452 KB n=3
4 Correct 47 ms 47452 KB n=4
5 Correct 46 ms 47492 KB n=4
6 Correct 50 ms 47492 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47352 KB n=4
2 Correct 49 ms 47452 KB n=3
3 Correct 49 ms 47452 KB n=3
4 Correct 47 ms 47452 KB n=4
5 Correct 46 ms 47492 KB n=4
6 Correct 50 ms 47492 KB n=2
7 Correct 47 ms 47648 KB n=5
8 Correct 50 ms 47648 KB n=8
9 Correct 51 ms 47648 KB n=14
10 Correct 49 ms 47648 KB n=11
11 Correct 147 ms 51424 KB n=50000
12 Correct 143 ms 51436 KB n=50000
13 Correct 52 ms 51436 KB n=10
14 Correct 50 ms 51436 KB n=685
15 Correct 51 ms 51436 KB n=623
16 Correct 51 ms 51436 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47352 KB n=4
2 Correct 49 ms 47452 KB n=3
3 Correct 49 ms 47452 KB n=3
4 Correct 47 ms 47452 KB n=4
5 Correct 46 ms 47492 KB n=4
6 Correct 50 ms 47492 KB n=2
7 Correct 47 ms 47648 KB n=5
8 Correct 50 ms 47648 KB n=8
9 Correct 51 ms 47648 KB n=14
10 Correct 49 ms 47648 KB n=11
11 Correct 147 ms 51424 KB n=50000
12 Correct 143 ms 51436 KB n=50000
13 Correct 52 ms 51436 KB n=10
14 Correct 50 ms 51436 KB n=685
15 Correct 51 ms 51436 KB n=623
16 Correct 51 ms 51436 KB n=973
17 Correct 45 ms 51436 KB n=989
18 Correct 43 ms 51436 KB n=563
19 Correct 48 ms 51436 KB n=592
20 Correct 46 ms 51436 KB n=938
21 Correct 49 ms 51436 KB n=747
22 Correct 64 ms 51436 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1762 ms 108852 KB n=1000000
2 Correct 992 ms 108852 KB n=666666
3 Correct 528 ms 108852 KB n=400000
4 Correct 1004 ms 108852 KB n=285714
5 Correct 70 ms 108852 KB n=20000
6 Correct 768 ms 108852 KB n=181818
7 Correct 60 ms 108852 KB n=10000
8 Correct 96 ms 108852 KB n=6666
9 Correct 53 ms 108852 KB n=4000
10 Correct 299 ms 108852 KB n=2857
11 Correct 56 ms 108852 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 51 ms 47352 KB n=4
2 Correct 49 ms 47452 KB n=3
3 Correct 49 ms 47452 KB n=3
4 Correct 47 ms 47452 KB n=4
5 Correct 46 ms 47492 KB n=4
6 Correct 50 ms 47492 KB n=2
7 Correct 47 ms 47648 KB n=5
8 Correct 50 ms 47648 KB n=8
9 Correct 51 ms 47648 KB n=14
10 Correct 49 ms 47648 KB n=11
11 Correct 147 ms 51424 KB n=50000
12 Correct 143 ms 51436 KB n=50000
13 Correct 52 ms 51436 KB n=10
14 Correct 50 ms 51436 KB n=685
15 Correct 51 ms 51436 KB n=623
16 Correct 51 ms 51436 KB n=973
17 Correct 45 ms 51436 KB n=989
18 Correct 43 ms 51436 KB n=563
19 Correct 48 ms 51436 KB n=592
20 Correct 46 ms 51436 KB n=938
21 Correct 49 ms 51436 KB n=747
22 Correct 64 ms 51436 KB n=991
23 Correct 1762 ms 108852 KB n=1000000
24 Correct 992 ms 108852 KB n=666666
25 Correct 528 ms 108852 KB n=400000
26 Correct 1004 ms 108852 KB n=285714
27 Correct 70 ms 108852 KB n=20000
28 Correct 768 ms 108852 KB n=181818
29 Correct 60 ms 108852 KB n=10000
30 Correct 96 ms 108852 KB n=6666
31 Correct 53 ms 108852 KB n=4000
32 Correct 299 ms 108852 KB n=2857
33 Correct 56 ms 108852 KB n=2000
34 Correct 110 ms 108852 KB n=23514
35 Correct 106 ms 108852 KB n=23514
36 Correct 51 ms 108852 KB n=940
37 Correct 47 ms 108852 KB n=2
38 Correct 332 ms 108852 KB n=100000
39 Correct 321 ms 108852 KB n=100000
40 Correct 43 ms 108852 KB n=10
41 Correct 46 ms 108852 KB n=100
42 Correct 50 ms 108852 KB n=1000
43 Execution timed out 2050 ms 134480 KB Time limit exceeded
44 Halted 0 ms 0 KB -