답안 #342210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342210 2021-01-01T15:39:05 Z David_M Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 48500 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const ll N=1000006, INF=1e18+2021;

ll n, k, x, s, mx, mn=INF, o, g;
pair<int, int> a[N];
priority_queue<pair<int,int> > q;

int main(){ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>k;
	
	for(int i=0;i<n;i++)
		cin>>x, s+=x, 
		mx=max(mx,x), 
		mn=min(mn,x),
		q.push({x,i+1}); 
	
	if(s%k||k*mx>s){cout<<-1; return 0;}
	
	if(mn==mx){
//		int g=__gcd(k, n);
		for (int i=1; i<=sqrt(mn); i++){
			if(mn%i==0){
				if((i*n)%k==0){
					x=i;
					break;
				}
				if((mn/i*n)%k==0){
					x=mn/i;
				}
			}
		}
		g=k/x;
//		cout<<g<<endl;
		cout<<n/g<<endl;
		for (int i=1; i<=n/g; i++){
			cout<<mn/x<<" ";
			for (int j=o; j<o+k; j++){
				cout<<(j%n)+1<<" ";
			}cout<<endl;
			o+=g;
			o%=n;
		}
		return 0;
	}
	
	cout<<s/k<<'\n';
	while(!q.empty()){
		cout<<1<<" ";
		for(int i=0;i<k;i++)
			a[i]=q.top(),
			q.pop();
		for(int i=0;i<k;i++){
			if(a[i].F>1)q.push({a[i].F-1, a[i].S});
			cout<<a[i].S<<" ";
		}
		cout<<'\n';
	}
}
/*
10 6
6 6 6 6 6 6 6 6 6 6
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 7 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 32 ms 1644 KB n=50000
12 Correct 40 ms 1644 KB n=50000
13 Correct 24 ms 748 KB n=10
14 Correct 21 ms 880 KB n=685
15 Correct 26 ms 876 KB n=623
16 Correct 13 ms 620 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 7 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 32 ms 1644 KB n=50000
12 Correct 40 ms 1644 KB n=50000
13 Correct 24 ms 748 KB n=10
14 Correct 21 ms 880 KB n=685
15 Correct 26 ms 876 KB n=623
16 Correct 13 ms 620 KB n=973
17 Correct 21 ms 876 KB n=989
18 Correct 10 ms 620 KB n=563
19 Correct 16 ms 748 KB n=592
20 Correct 17 ms 748 KB n=938
21 Correct 21 ms 620 KB n=747
22 Correct 20 ms 748 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 1516 ms 22756 KB n=1000000
2 Correct 732 ms 18208 KB n=666666
3 Correct 346 ms 12140 KB n=400000
4 Correct 936 ms 23900 KB n=285714
5 Correct 7 ms 1008 KB n=20000
6 Correct 646 ms 19816 KB n=181818
7 Correct 4 ms 896 KB n=10000
8 Correct 35 ms 2156 KB n=6666
9 Correct 3 ms 492 KB n=4000
10 Correct 187 ms 9736 KB n=2857
11 Correct 1 ms 492 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 7 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 32 ms 1644 KB n=50000
12 Correct 40 ms 1644 KB n=50000
13 Correct 24 ms 748 KB n=10
14 Correct 21 ms 880 KB n=685
15 Correct 26 ms 876 KB n=623
16 Correct 13 ms 620 KB n=973
17 Correct 21 ms 876 KB n=989
18 Correct 10 ms 620 KB n=563
19 Correct 16 ms 748 KB n=592
20 Correct 17 ms 748 KB n=938
21 Correct 21 ms 620 KB n=747
22 Correct 20 ms 748 KB n=991
23 Correct 1516 ms 22756 KB n=1000000
24 Correct 732 ms 18208 KB n=666666
25 Correct 346 ms 12140 KB n=400000
26 Correct 936 ms 23900 KB n=285714
27 Correct 7 ms 1008 KB n=20000
28 Correct 646 ms 19816 KB n=181818
29 Correct 4 ms 896 KB n=10000
30 Correct 35 ms 2156 KB n=6666
31 Correct 3 ms 492 KB n=4000
32 Correct 187 ms 9736 KB n=2857
33 Correct 1 ms 492 KB n=2000
34 Execution timed out 2054 ms 48500 KB Time limit exceeded
35 Halted 0 ms 0 KB -