Submission #237257

# Submission time Handle Problem Language Result Execution time Memory
237257 2020-06-05T13:17:20 Z kshitij_sodani Gift (IZhO18_nicegift) C++17
49 / 100
2000 ms 329280 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo it[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n,k;
	cin>>n>>k;
	priority_queue<pair<llo,llo>> x;
	llo ko=1;
	for(llo i=0;i<n;i++){
		cin>>it[i];
		if(it[i]>0){
			x.push({it[i],i});
		}
		if(i>0){
			if(it[i]!=it[i-1]){
				ko=0;
			}
		}
	}
	if(ko){
		llo aa=n/__gcd(n,k);
	//	cout<<aa<<endl;
		if((it[0]*n)%(aa*k)!=0){
			cout<<-1<<endl;
			return 0;
		}
		deque<llo> cur;
		for(llo i=0;i<n;i++){
			cur.pb(i);
		}
		cout<<aa<<endl;
		for(llo i=0;i<aa;i++){
			cout<<((it[0]*n)/(aa*k))<<" ";
			for(llo j=0;j<k;j++){
				llo x=cur.front();
				cur.pop_front();
				cur.pb(x);
				cout<<x+1<<" ";
			}
			cout<<endl;
		}

		return 0;
	}
	llo st=0;
	vector<vector<llo>> ans;
	while(x.size()){
		if(x.size()<k){
			st=1;
			break;
		}
		ans.pb({});
		vector<pair<llo,llo>> kk;
		for(llo i=0;i<k;i++){
			pair<llo,llo> no=x.top();
			x.pop();
			ans.back().pb(no.b);
			kk.pb(no);
		}
		for(auto j:kk){
			if(j.a>1){
				x.push({j.a-1,j.b});
			}
		}
	}
	if(st){
		cout<<-1<<endl;
	}
	else{
		cout<<ans.size()<<endl;
		for(auto j:ans){
			cout<<1<<" ";
			for(auto i:j){
				cout<<i+1<<" ";
			}
			cout<<endl;
		}
	}




 
 
 
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:55:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(x.size()<k){
      ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB n=4
2 Correct 5 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 4 ms 384 KB n=4
6 Correct 5 ms 384 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB n=4
2 Correct 5 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 4 ms 384 KB n=4
6 Correct 5 ms 384 KB n=2
7 Correct 5 ms 384 KB n=5
8 Correct 7 ms 1024 KB n=8
9 Correct 42 ms 1212 KB n=14
10 Correct 27 ms 1024 KB n=11
11 Correct 141 ms 5228 KB n=50000
12 Correct 148 ms 5356 KB n=50000
13 Correct 125 ms 3496 KB n=10
14 Correct 111 ms 3084 KB n=685
15 Correct 121 ms 3368 KB n=623
16 Correct 67 ms 2048 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB n=4
2 Correct 5 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 4 ms 384 KB n=4
6 Correct 5 ms 384 KB n=2
7 Correct 5 ms 384 KB n=5
8 Correct 7 ms 1024 KB n=8
9 Correct 42 ms 1212 KB n=14
10 Correct 27 ms 1024 KB n=11
11 Correct 141 ms 5228 KB n=50000
12 Correct 148 ms 5356 KB n=50000
13 Correct 125 ms 3496 KB n=10
14 Correct 111 ms 3084 KB n=685
15 Correct 121 ms 3368 KB n=623
16 Correct 67 ms 2048 KB n=973
17 Correct 98 ms 3048 KB n=989
18 Correct 30 ms 1280 KB n=563
19 Correct 33 ms 2048 KB n=592
20 Correct 37 ms 1920 KB n=938
21 Correct 36 ms 1784 KB n=747
22 Correct 33 ms 1664 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1388 ms 46668 KB n=1000000
2 Correct 661 ms 30144 KB n=666666
3 Correct 296 ms 17596 KB n=400000
4 Correct 828 ms 27448 KB n=285714
5 Correct 12 ms 1408 KB n=20000
6 Correct 571 ms 22420 KB n=181818
7 Correct 8 ms 896 KB n=10000
8 Correct 37 ms 2460 KB n=6666
9 Correct 6 ms 640 KB n=4000
10 Correct 179 ms 9848 KB n=2857
11 Correct 5 ms 512 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB n=4
2 Correct 5 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 4 ms 384 KB n=4
6 Correct 5 ms 384 KB n=2
7 Correct 5 ms 384 KB n=5
8 Correct 7 ms 1024 KB n=8
9 Correct 42 ms 1212 KB n=14
10 Correct 27 ms 1024 KB n=11
11 Correct 141 ms 5228 KB n=50000
12 Correct 148 ms 5356 KB n=50000
13 Correct 125 ms 3496 KB n=10
14 Correct 111 ms 3084 KB n=685
15 Correct 121 ms 3368 KB n=623
16 Correct 67 ms 2048 KB n=973
17 Correct 98 ms 3048 KB n=989
18 Correct 30 ms 1280 KB n=563
19 Correct 33 ms 2048 KB n=592
20 Correct 37 ms 1920 KB n=938
21 Correct 36 ms 1784 KB n=747
22 Correct 33 ms 1664 KB n=991
23 Correct 1388 ms 46668 KB n=1000000
24 Correct 661 ms 30144 KB n=666666
25 Correct 296 ms 17596 KB n=400000
26 Correct 828 ms 27448 KB n=285714
27 Correct 12 ms 1408 KB n=20000
28 Correct 571 ms 22420 KB n=181818
29 Correct 8 ms 896 KB n=10000
30 Correct 37 ms 2460 KB n=6666
31 Correct 6 ms 640 KB n=4000
32 Correct 179 ms 9848 KB n=2857
33 Correct 5 ms 512 KB n=2000
34 Execution timed out 2095 ms 329280 KB Time limit exceeded
35 Halted 0 ms 0 KB -