# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
168940 | 2019-12-17T09:04:56 Z | abil | Gift (IZhO18_nicegift) | C++14 | 2000 ms | 129516 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() #define int long long using namespace std; const int N = (1e6 + 12); const int mod = (1e9 + 7); const int INF = (1e18 + 12); int a[N], b[N]; vector<pair<int,int > > vec[N]; vector<int > ans[N]; int res[N]; main() { int n, k, sum = 0, mx = 0; scanf("%lld%lld", &n, &k); for(int i = 1;i <= n; i++){ scanf("%lld", &a[i]); sum += a[i]; mx = max(mx, a[i]); } if(sum % k != 0 || mx > sum / k){ cout << -1; return 0; } int cur_sum = 0; int sz = 0; for(int i = 1;i <= n; i++){ cur_sum += a[i]; if(cur_sum >= sum / k){ int rem = cur_sum - sum / k; cur_sum = rem; vec[sz].pb({a[i] - rem, i}); sz++; if(rem > 0){ vec[sz].pb({rem, i}); } } else{ vec[sz].pb({a[i], i}); } } int szofans = 1; while(1){ int mn = INF; for(int i = 0;i < sz; i++){ mn = min(mn, vec[i][b[i]].fr); } res[szofans] = mn; bool f = false; for(int i = 0;i < sz; i++){ vec[i][b[i]].fr -= mn; ans[szofans].pb(vec[i][b[i]].sc); if(vec[i][b[i]].fr == 0){ b[i]++; if(b[i] == vec[i].size()){ f = true; } } } if(f){ break; } szofans++; } cout << szofans << endl; for(int i = 1;i <= szofans; i++){ cout << res[i] << " "; for(auto to : ans[i]){ cout << to << " "; } cout << endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47344 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 45 ms | 47352 KB | n=3 |
4 | Correct | 45 ms | 47352 KB | n=4 |
5 | Correct | 45 ms | 47236 KB | n=4 |
6 | Correct | 45 ms | 47352 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47344 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 45 ms | 47352 KB | n=3 |
4 | Correct | 45 ms | 47352 KB | n=4 |
5 | Correct | 45 ms | 47236 KB | n=4 |
6 | Correct | 45 ms | 47352 KB | n=2 |
7 | Correct | 45 ms | 47232 KB | n=5 |
8 | Correct | 45 ms | 47452 KB | n=8 |
9 | Correct | 45 ms | 47456 KB | n=14 |
10 | Correct | 45 ms | 47224 KB | n=11 |
11 | Correct | 181 ms | 50916 KB | n=50000 |
12 | Correct | 174 ms | 50800 KB | n=50000 |
13 | Correct | 45 ms | 47224 KB | n=10 |
14 | Correct | 48 ms | 47356 KB | n=685 |
15 | Correct | 47 ms | 47356 KB | n=623 |
16 | Correct | 49 ms | 47360 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47344 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 45 ms | 47352 KB | n=3 |
4 | Correct | 45 ms | 47352 KB | n=4 |
5 | Correct | 45 ms | 47236 KB | n=4 |
6 | Correct | 45 ms | 47352 KB | n=2 |
7 | Correct | 45 ms | 47232 KB | n=5 |
8 | Correct | 45 ms | 47452 KB | n=8 |
9 | Correct | 45 ms | 47456 KB | n=14 |
10 | Correct | 45 ms | 47224 KB | n=11 |
11 | Correct | 181 ms | 50916 KB | n=50000 |
12 | Correct | 174 ms | 50800 KB | n=50000 |
13 | Correct | 45 ms | 47224 KB | n=10 |
14 | Correct | 48 ms | 47356 KB | n=685 |
15 | Correct | 47 ms | 47356 KB | n=623 |
16 | Correct | 49 ms | 47360 KB | n=973 |
17 | Correct | 49 ms | 47368 KB | n=989 |
18 | Correct | 48 ms | 47352 KB | n=563 |
19 | Correct | 49 ms | 47480 KB | n=592 |
20 | Correct | 50 ms | 47480 KB | n=938 |
21 | Correct | 49 ms | 47480 KB | n=747 |
22 | Correct | 50 ms | 47480 KB | n=991 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1796 ms | 105136 KB | n=1000000 |
2 | Correct | 910 ms | 83312 KB | n=666666 |
3 | Correct | 417 ms | 67768 KB | n=400000 |
4 | Correct | 1197 ms | 96256 KB | n=285714 |
5 | Correct | 52 ms | 48376 KB | n=20000 |
6 | Correct | 882 ms | 94164 KB | n=181818 |
7 | Correct | 49 ms | 47864 KB | n=10000 |
8 | Correct | 91 ms | 54008 KB | n=6666 |
9 | Correct | 47 ms | 47480 KB | n=4000 |
10 | Correct | 300 ms | 79864 KB | n=2857 |
11 | Correct | 56 ms | 47480 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 47344 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 45 ms | 47352 KB | n=3 |
4 | Correct | 45 ms | 47352 KB | n=4 |
5 | Correct | 45 ms | 47236 KB | n=4 |
6 | Correct | 45 ms | 47352 KB | n=2 |
7 | Correct | 45 ms | 47232 KB | n=5 |
8 | Correct | 45 ms | 47452 KB | n=8 |
9 | Correct | 45 ms | 47456 KB | n=14 |
10 | Correct | 45 ms | 47224 KB | n=11 |
11 | Correct | 181 ms | 50916 KB | n=50000 |
12 | Correct | 174 ms | 50800 KB | n=50000 |
13 | Correct | 45 ms | 47224 KB | n=10 |
14 | Correct | 48 ms | 47356 KB | n=685 |
15 | Correct | 47 ms | 47356 KB | n=623 |
16 | Correct | 49 ms | 47360 KB | n=973 |
17 | Correct | 49 ms | 47368 KB | n=989 |
18 | Correct | 48 ms | 47352 KB | n=563 |
19 | Correct | 49 ms | 47480 KB | n=592 |
20 | Correct | 50 ms | 47480 KB | n=938 |
21 | Correct | 49 ms | 47480 KB | n=747 |
22 | Correct | 50 ms | 47480 KB | n=991 |
23 | Correct | 1796 ms | 105136 KB | n=1000000 |
24 | Correct | 910 ms | 83312 KB | n=666666 |
25 | Correct | 417 ms | 67768 KB | n=400000 |
26 | Correct | 1197 ms | 96256 KB | n=285714 |
27 | Correct | 52 ms | 48376 KB | n=20000 |
28 | Correct | 882 ms | 94164 KB | n=181818 |
29 | Correct | 49 ms | 47864 KB | n=10000 |
30 | Correct | 91 ms | 54008 KB | n=6666 |
31 | Correct | 47 ms | 47480 KB | n=4000 |
32 | Correct | 300 ms | 79864 KB | n=2857 |
33 | Correct | 56 ms | 47480 KB | n=2000 |
34 | Correct | 123 ms | 49464 KB | n=23514 |
35 | Correct | 122 ms | 49304 KB | n=23514 |
36 | Correct | 48 ms | 47424 KB | n=940 |
37 | Correct | 45 ms | 47352 KB | n=2 |
38 | Correct | 410 ms | 61952 KB | n=100000 |
39 | Correct | 412 ms | 62084 KB | n=100000 |
40 | Correct | 45 ms | 47352 KB | n=10 |
41 | Correct | 46 ms | 47352 KB | n=100 |
42 | Correct | 54 ms | 48120 KB | n=1000 |
43 | Execution timed out | 2072 ms | 129516 KB | Time limit exceeded |
44 | Halted | 0 ms | 0 KB | - |