Submission #237256

# Submission time Handle Problem Language Result Execution time Memory
237256 2020-06-05T13:15:24 Z kshitij_sodani Gift (IZhO18_nicegift) C++17
49 / 100
2000 ms 329640 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!=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 4 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 5 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 4 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 5 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 40 ms 1212 KB n=14
10 Correct 26 ms 1024 KB n=11
11 Correct 143 ms 5096 KB n=50000
12 Correct 135 ms 5140 KB n=50000
13 Correct 123 ms 3496 KB n=10
14 Correct 109 ms 3116 KB n=685
15 Correct 119 ms 3368 KB n=623
16 Correct 71 ms 2224 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB n=4
2 Correct 4 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 5 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 40 ms 1212 KB n=14
10 Correct 26 ms 1024 KB n=11
11 Correct 143 ms 5096 KB n=50000
12 Correct 135 ms 5140 KB n=50000
13 Correct 123 ms 3496 KB n=10
14 Correct 109 ms 3116 KB n=685
15 Correct 119 ms 3368 KB n=623
16 Correct 71 ms 2224 KB n=973
17 Correct 94 ms 3116 KB n=989
18 Correct 30 ms 1280 KB n=563
19 Correct 42 ms 2040 KB n=592
20 Correct 45 ms 1784 KB n=938
21 Correct 34 ms 1792 KB n=747
22 Correct 35 ms 1784 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1308 ms 46692 KB n=1000000
2 Correct 687 ms 38860 KB n=666666
3 Correct 292 ms 22664 KB n=400000
4 Correct 799 ms 30804 KB n=285714
5 Correct 12 ms 1408 KB n=20000
6 Correct 577 ms 24160 KB n=181818
7 Correct 8 ms 896 KB n=10000
8 Correct 36 ms 2304 KB n=6666
9 Correct 6 ms 640 KB n=4000
10 Correct 169 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 4 ms 384 KB n=3
3 Correct 5 ms 384 KB n=3
4 Correct 5 ms 384 KB n=4
5 Correct 5 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 40 ms 1212 KB n=14
10 Correct 26 ms 1024 KB n=11
11 Correct 143 ms 5096 KB n=50000
12 Correct 135 ms 5140 KB n=50000
13 Correct 123 ms 3496 KB n=10
14 Correct 109 ms 3116 KB n=685
15 Correct 119 ms 3368 KB n=623
16 Correct 71 ms 2224 KB n=973
17 Correct 94 ms 3116 KB n=989
18 Correct 30 ms 1280 KB n=563
19 Correct 42 ms 2040 KB n=592
20 Correct 45 ms 1784 KB n=938
21 Correct 34 ms 1792 KB n=747
22 Correct 35 ms 1784 KB n=991
23 Correct 1308 ms 46692 KB n=1000000
24 Correct 687 ms 38860 KB n=666666
25 Correct 292 ms 22664 KB n=400000
26 Correct 799 ms 30804 KB n=285714
27 Correct 12 ms 1408 KB n=20000
28 Correct 577 ms 24160 KB n=181818
29 Correct 8 ms 896 KB n=10000
30 Correct 36 ms 2304 KB n=6666
31 Correct 6 ms 640 KB n=4000
32 Correct 169 ms 9848 KB n=2857
33 Correct 5 ms 512 KB n=2000
34 Execution timed out 2089 ms 329640 KB Time limit exceeded
35 Halted 0 ms 0 KB -