답안 #495497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495497 2021-12-19T03:39:16 Z mansur Gift (IZhO18_nicegift) C++14
100 / 100
524 ms 122760 KB
#include<bits/stdc++.h>	
 
#pragma optimize ("g",on)
#pragma GCC optimize("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")

//01001101 01100001 01101011 01101000 01100001  01100111 01100001 01111001 

using namespace std;

#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()                                                                   
#define ld double
#define ull unsigned long long
#define ff first                                         
#define ss second  
#define fix fixed << setprecision
#define pii pair<int, int>                          
#define E exit (0)
#define int long long
 
const int inf = 1e18, N = 1e5 + 1, mod = 998244353;                    

vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

main() {    	                                                     
	//freopen("cowrect.in", "r", stdin);                                                                                     
	//freopen("cowrect.out", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(NULL);                                                                                        
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	int a[n + 1];
	for (int i = 1; i <= n; i++) cin >> a[i];
	int sum = 0, mx = 0;
	for (int i = 1; i <= n; i++) sum += a[i], mx = max(mx, a[i]);
	if (sum % k || mx > sum / k) cout << -1, E;
	vector<vector<pii>> s;
	vector<pii> cur;
	int sm = 0;
	sum /= k;
	for (int i = 1; i <= n; i++) {
		if (sm + a[i] <= sum) {
			cur.pb({a[i], i});
			sm += a[i];	
		}else {
			cur.pb({sum - sm, i});
			s.pb(cur);
			cur.clear();
			a[i] -= sum - sm;
			sm = 0;
			i--;
		}
		if (sm == sum) {
			s.pb(cur);
			cur.clear();
			sm = 0;
		}
	}
	vector<pair<int, vector<int>>> ans;
	while (sz(s[0])) {
		vector<int> h;
		int mn = inf;
		for (auto &e: s) {
			mn = min(mn, e.back().ff);
		}             
		if (mn == inf) break;
		for (auto &e: s) {
			e.back().ff -= mn;
			h.pb(e.back().ss);
			if (!e.back().ff) {
				e.popb;
			}
		}
		ans.pb({mn, h});
	}
	cout << sz(ans) << nl;
	for (auto e: ans) {
		cout << e.ff << ' ';
		for (auto x: e.ss) cout << x << ' ';
		cout << nl;
	}
}

Compilation message

nicegift.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
nicegift.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 308 KB n=4
5 Correct 1 ms 312 KB n=4
6 Correct 0 ms 204 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 308 KB n=4
5 Correct 1 ms 312 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 312 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 19 ms 5300 KB n=50000
12 Correct 17 ms 5060 KB n=50000
13 Correct 1 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 308 KB n=4
5 Correct 1 ms 312 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 312 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 19 ms 5300 KB n=50000
12 Correct 17 ms 5060 KB n=50000
13 Correct 1 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
17 Correct 1 ms 308 KB n=989
18 Correct 1 ms 332 KB n=563
19 Correct 1 ms 444 KB n=592
20 Correct 1 ms 444 KB n=938
21 Correct 1 ms 460 KB n=747
22 Correct 2 ms 460 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 77464 KB n=1000000
2 Correct 200 ms 44080 KB n=666666
3 Correct 110 ms 23836 KB n=400000
4 Correct 275 ms 54568 KB n=285714
5 Correct 5 ms 1324 KB n=20000
6 Correct 231 ms 45492 KB n=181818
7 Correct 3 ms 800 KB n=10000
8 Correct 28 ms 4780 KB n=6666
9 Correct 1 ms 452 KB n=4000
10 Correct 143 ms 25480 KB n=2857
11 Correct 1 ms 460 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 308 KB n=4
5 Correct 1 ms 312 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 312 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 19 ms 5300 KB n=50000
12 Correct 17 ms 5060 KB n=50000
13 Correct 1 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
17 Correct 1 ms 308 KB n=989
18 Correct 1 ms 332 KB n=563
19 Correct 1 ms 444 KB n=592
20 Correct 1 ms 444 KB n=938
21 Correct 1 ms 460 KB n=747
22 Correct 2 ms 460 KB n=991
23 Correct 323 ms 77464 KB n=1000000
24 Correct 200 ms 44080 KB n=666666
25 Correct 110 ms 23836 KB n=400000
26 Correct 275 ms 54568 KB n=285714
27 Correct 5 ms 1324 KB n=20000
28 Correct 231 ms 45492 KB n=181818
29 Correct 3 ms 800 KB n=10000
30 Correct 28 ms 4780 KB n=6666
31 Correct 1 ms 452 KB n=4000
32 Correct 143 ms 25480 KB n=2857
33 Correct 1 ms 460 KB n=2000
34 Correct 12 ms 3012 KB n=23514
35 Correct 11 ms 3012 KB n=23514
36 Correct 1 ms 288 KB n=940
37 Correct 0 ms 204 KB n=2
38 Correct 71 ms 14320 KB n=100000
39 Correct 71 ms 14456 KB n=100000
40 Correct 0 ms 204 KB n=10
41 Correct 1 ms 332 KB n=100
42 Correct 5 ms 972 KB n=1000
43 Correct 477 ms 121952 KB n=1000000
44 Correct 524 ms 122760 KB n=1000000
45 Correct 432 ms 85328 KB n=666666
46 Correct 322 ms 62804 KB n=400000
47 Correct 142 ms 25476 KB n=2336
48 Correct 266 ms 54492 KB n=285714
49 Correct 236 ms 45584 KB n=181818
50 Correct 164 ms 31164 KB n=40000
51 Correct 158 ms 28768 KB n=20000
52 Correct 145 ms 26676 KB n=10000
53 Correct 145 ms 26300 KB n=6666
54 Correct 142 ms 25632 KB n=4000
55 Correct 145 ms 25588 KB n=2857
56 Correct 145 ms 24644 KB n=2000