답안 #1107892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107892 2024-11-02T09:41:24 Z Muhammet Gift (IZhO18_nicegift) C++17
30 / 100
34 ms 4288 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(s) (int)s.size()
#define ff first
#define ss second

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	multiset <pair<int,int>> s;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] == 0) continue;
		s.insert({a[i],i+1});
	}
	vector <pair<int,int>> v1;
	vector <int> v;
	while(sz(s) >= k){
		v1.clear();
		for(int i = 0; i < k; i++){
			v1.push_back(*(--s.end()));
			s.erase(--s.end());
		}
		for(int i = 0; i < k; i++){
			v1.back().ff--;
			if(v1.back().ff != 0) s.insert(v1.back());
			v.push_back(v1.back().ss);
			v1.pop_back();
		}
	}
	if(sz(s) > 0){
		cout << -1;
		return 0;
	}
	reverse(v.begin(), v.end());
	cout << sz(v)/k << "\n";
	int x = sz(v)/k;
	while(x--){
		cout << 1 << " ";
		int cnt = k;
		while(cnt--){
			cout << v.back() << ' ';
			v.pop_back();
		}
		cout << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB n=4
2 Correct 1 ms 460 KB n=3
3 Correct 1 ms 504 KB n=3
4 Correct 1 ms 336 KB n=4
5 Correct 1 ms 504 KB n=4
6 Correct 1 ms 336 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB n=4
2 Correct 1 ms 460 KB n=3
3 Correct 1 ms 504 KB n=3
4 Correct 1 ms 336 KB n=4
5 Correct 1 ms 504 KB n=4
6 Correct 1 ms 336 KB n=2
7 Correct 1 ms 336 KB n=5
8 Correct 1 ms 592 KB n=8
9 Correct 4 ms 592 KB n=14
10 Correct 3 ms 764 KB n=11
11 Correct 20 ms 4288 KB n=50000
12 Correct 34 ms 3788 KB n=50000
13 Correct 13 ms 1400 KB n=10
14 Correct 13 ms 1224 KB n=685
15 Correct 14 ms 1292 KB n=623
16 Correct 9 ms 972 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB n=4
2 Correct 1 ms 460 KB n=3
3 Correct 1 ms 504 KB n=3
4 Correct 1 ms 336 KB n=4
5 Correct 1 ms 504 KB n=4
6 Correct 1 ms 336 KB n=2
7 Correct 1 ms 336 KB n=5
8 Correct 1 ms 592 KB n=8
9 Correct 4 ms 592 KB n=14
10 Correct 3 ms 764 KB n=11
11 Correct 20 ms 4288 KB n=50000
12 Correct 34 ms 3788 KB n=50000
13 Correct 13 ms 1400 KB n=10
14 Correct 13 ms 1224 KB n=685
15 Correct 14 ms 1292 KB n=623
16 Correct 9 ms 972 KB n=973
17 Correct 14 ms 1392 KB n=989
18 Correct 7 ms 980 KB n=563
19 Correct 21 ms 1224 KB n=592
20 Correct 12 ms 1224 KB n=938
21 Correct 9 ms 1140 KB n=747
22 Correct 11 ms 1224 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 4176 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB n=4
2 Correct 1 ms 460 KB n=3
3 Correct 1 ms 504 KB n=3
4 Correct 1 ms 336 KB n=4
5 Correct 1 ms 504 KB n=4
6 Correct 1 ms 336 KB n=2
7 Correct 1 ms 336 KB n=5
8 Correct 1 ms 592 KB n=8
9 Correct 4 ms 592 KB n=14
10 Correct 3 ms 764 KB n=11
11 Correct 20 ms 4288 KB n=50000
12 Correct 34 ms 3788 KB n=50000
13 Correct 13 ms 1400 KB n=10
14 Correct 13 ms 1224 KB n=685
15 Correct 14 ms 1292 KB n=623
16 Correct 9 ms 972 KB n=973
17 Correct 14 ms 1392 KB n=989
18 Correct 7 ms 980 KB n=563
19 Correct 21 ms 1224 KB n=592
20 Correct 12 ms 1224 KB n=938
21 Correct 9 ms 1140 KB n=747
22 Correct 11 ms 1224 KB n=991
23 Incorrect 8 ms 4176 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -