Submission #237255

# Submission time Handle Problem Language Result Execution time Memory
237255 2020-06-05T13:14:31 Z kshitij_sodani Gift (IZhO18_nicegift) C++17
30 / 100
145 ms 4480 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
int it[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	priority_queue<pair<int,int>> x;
	int ko=1;
	for(int 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){
		int aa=n/__gcd(n,k);
	//	cout<<aa<<endl;
		if((it[0]*n)%aa!=0){
			cout<<-1<<endl;
			return 0;
		}
		deque<int> cur;
		for(int i=0;i<n;i++){
			cur.pb(i);
		}
		cout<<aa<<endl;
		for(int i=0;i<aa;i++){
			cout<<((it[0]*n)/(aa*k))<<" ";
			for(int j=0;j<k;j++){
				int x=cur.front();
				cur.pop_front();
				cur.pb(x);
				cout<<x+1<<" ";
			}
			cout<<endl;
		}

		return 0;
	}
	int st=0;
	vector<vector<int>> ans;
	while(x.size()){
		if(x.size()<k){
			st=1;
			break;
		}
		ans.pb({});
		vector<pair<int,int>> kk;
		for(int i=0;i<k;i++){
			pair<int,int> 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 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 4 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 40 ms 1212 KB n=14
10 Correct 25 ms 1024 KB n=11
11 Correct 143 ms 4480 KB n=50000
12 Correct 145 ms 4456 KB n=50000
13 Correct 130 ms 3500 KB n=10
14 Correct 115 ms 3092 KB n=685
15 Correct 129 ms 3368 KB n=623
16 Correct 70 ms 1968 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 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 40 ms 1212 KB n=14
10 Correct 25 ms 1024 KB n=11
11 Correct 143 ms 4480 KB n=50000
12 Correct 145 ms 4456 KB n=50000
13 Correct 130 ms 3500 KB n=10
14 Correct 115 ms 3092 KB n=685
15 Correct 129 ms 3368 KB n=623
16 Correct 70 ms 1968 KB n=973
17 Correct 91 ms 2608 KB n=989
18 Correct 30 ms 1024 KB n=563
19 Correct 35 ms 1536 KB n=592
20 Correct 36 ms 1400 KB n=938
21 Correct 34 ms 1400 KB n=747
22 Correct 34 ms 1400 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 384 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 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 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 40 ms 1212 KB n=14
10 Correct 25 ms 1024 KB n=11
11 Correct 143 ms 4480 KB n=50000
12 Correct 145 ms 4456 KB n=50000
13 Correct 130 ms 3500 KB n=10
14 Correct 115 ms 3092 KB n=685
15 Correct 129 ms 3368 KB n=623
16 Correct 70 ms 1968 KB n=973
17 Correct 91 ms 2608 KB n=989
18 Correct 30 ms 1024 KB n=563
19 Correct 35 ms 1536 KB n=592
20 Correct 36 ms 1400 KB n=938
21 Correct 34 ms 1400 KB n=747
22 Correct 34 ms 1400 KB n=991
23 Incorrect 12 ms 384 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -