답안 #89507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89507 2018-12-15T07:01:00 Z Hideo Gift (IZhO18_nicegift) C++14
100 / 100
890 ms 144604 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++){
        scanf("%lld", &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++){
            printf("%lld ", ans[it][i]);
        }
        printf("\n");
        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++){
                         ~~^~~~~~~~~~~~~~~~
nicegift.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47320 KB n=4
2 Correct 42 ms 47356 KB n=3
3 Correct 49 ms 47356 KB n=3
4 Correct 42 ms 47460 KB n=4
5 Correct 42 ms 47536 KB n=4
6 Correct 45 ms 47552 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47320 KB n=4
2 Correct 42 ms 47356 KB n=3
3 Correct 49 ms 47356 KB n=3
4 Correct 42 ms 47460 KB n=4
5 Correct 42 ms 47536 KB n=4
6 Correct 45 ms 47552 KB n=2
7 Correct 42 ms 47556 KB n=5
8 Correct 44 ms 47556 KB n=8
9 Correct 42 ms 47556 KB n=14
10 Correct 42 ms 47592 KB n=11
11 Correct 70 ms 51548 KB n=50000
12 Correct 68 ms 51548 KB n=50000
13 Correct 42 ms 51548 KB n=10
14 Correct 42 ms 51548 KB n=685
15 Correct 42 ms 51548 KB n=623
16 Correct 42 ms 51548 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47320 KB n=4
2 Correct 42 ms 47356 KB n=3
3 Correct 49 ms 47356 KB n=3
4 Correct 42 ms 47460 KB n=4
5 Correct 42 ms 47536 KB n=4
6 Correct 45 ms 47552 KB n=2
7 Correct 42 ms 47556 KB n=5
8 Correct 44 ms 47556 KB n=8
9 Correct 42 ms 47556 KB n=14
10 Correct 42 ms 47592 KB n=11
11 Correct 70 ms 51548 KB n=50000
12 Correct 68 ms 51548 KB n=50000
13 Correct 42 ms 51548 KB n=10
14 Correct 42 ms 51548 KB n=685
15 Correct 42 ms 51548 KB n=623
16 Correct 42 ms 51548 KB n=973
17 Correct 42 ms 51548 KB n=989
18 Correct 42 ms 51548 KB n=563
19 Correct 44 ms 51548 KB n=592
20 Correct 52 ms 51548 KB n=938
21 Correct 47 ms 51548 KB n=747
22 Correct 46 ms 51548 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 529 ms 108700 KB n=1000000
2 Correct 352 ms 108700 KB n=666666
3 Correct 221 ms 108700 KB n=400000
4 Correct 465 ms 108700 KB n=285714
5 Correct 58 ms 108700 KB n=20000
6 Correct 414 ms 108700 KB n=181818
7 Correct 48 ms 108700 KB n=10000
8 Correct 83 ms 108700 KB n=6666
9 Correct 43 ms 108700 KB n=4000
10 Correct 281 ms 108700 KB n=2857
11 Correct 50 ms 108700 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 47320 KB n=4
2 Correct 42 ms 47356 KB n=3
3 Correct 49 ms 47356 KB n=3
4 Correct 42 ms 47460 KB n=4
5 Correct 42 ms 47536 KB n=4
6 Correct 45 ms 47552 KB n=2
7 Correct 42 ms 47556 KB n=5
8 Correct 44 ms 47556 KB n=8
9 Correct 42 ms 47556 KB n=14
10 Correct 42 ms 47592 KB n=11
11 Correct 70 ms 51548 KB n=50000
12 Correct 68 ms 51548 KB n=50000
13 Correct 42 ms 51548 KB n=10
14 Correct 42 ms 51548 KB n=685
15 Correct 42 ms 51548 KB n=623
16 Correct 42 ms 51548 KB n=973
17 Correct 42 ms 51548 KB n=989
18 Correct 42 ms 51548 KB n=563
19 Correct 44 ms 51548 KB n=592
20 Correct 52 ms 51548 KB n=938
21 Correct 47 ms 51548 KB n=747
22 Correct 46 ms 51548 KB n=991
23 Correct 529 ms 108700 KB n=1000000
24 Correct 352 ms 108700 KB n=666666
25 Correct 221 ms 108700 KB n=400000
26 Correct 465 ms 108700 KB n=285714
27 Correct 58 ms 108700 KB n=20000
28 Correct 414 ms 108700 KB n=181818
29 Correct 48 ms 108700 KB n=10000
30 Correct 83 ms 108700 KB n=6666
31 Correct 43 ms 108700 KB n=4000
32 Correct 281 ms 108700 KB n=2857
33 Correct 50 ms 108700 KB n=2000
34 Correct 65 ms 108700 KB n=23514
35 Correct 68 ms 108700 KB n=23514
36 Correct 51 ms 108700 KB n=940
37 Correct 50 ms 108700 KB n=2
38 Correct 158 ms 108700 KB n=100000
39 Correct 158 ms 108700 KB n=100000
40 Correct 51 ms 108700 KB n=10
41 Correct 51 ms 108700 KB n=100
42 Correct 54 ms 108700 KB n=1000
43 Correct 810 ms 139216 KB n=1000000
44 Correct 890 ms 144604 KB n=1000000
45 Correct 699 ms 144604 KB n=666666
46 Correct 575 ms 144604 KB n=400000
47 Correct 268 ms 144604 KB n=2336
48 Correct 469 ms 144604 KB n=285714
49 Correct 417 ms 144604 KB n=181818
50 Correct 325 ms 144604 KB n=40000
51 Correct 314 ms 144604 KB n=20000
52 Correct 292 ms 144604 KB n=10000
53 Correct 282 ms 144604 KB n=6666
54 Correct 268 ms 144604 KB n=4000
55 Correct 293 ms 144604 KB n=2857
56 Correct 272 ms 144604 KB n=2000