답안 #378786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378786 2021-03-17T04:11:34 Z iris2617 Gift (IZhO18_nicegift) C++14
100 / 100
1189 ms 89212 KB
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
#define iris 1000000007
using namespace std;

priority_queue<matsuri> pq;
int arr[1000010];
vector<pair<int, vector<int> > > ans;
vector<int> ouo;

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,k,i,a,x,noel,nonoka,sum=0;
	
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
		pq.push({arr[i],i});
	}
	while(pq.size()>=k)
	{
//		char c;
//		cin>>c;
		ouo.clear();
		for(i=0;i<k;i++)
		{
			ouo.emplace_back(pq.top().second);
			nonoka=pq.top().first;
			pq.pop();
		}
		noel=pq.top().first;
		if(!pq.empty())
			x=min((sum-noel*k)/k, nonoka);
		else
			x=nonoka;
//		cout<<x<<endl;
		sum-=x*k;
		ans.emplace_back(x,ouo);
		for(int aoi:ouo)
		{
			arr[aoi]-=x;
			if(arr[aoi])
				pq.push({arr[aoi],aoi});
		}
	}
	if(pq.empty())
	{
		cout<<ans.size()<<'\n';
		for(auto sana:ans)
		{
			cout<<sana.first;
			for(int aoi:sana.second)
			{
				cout<<" "<<aoi;
			}
			cout<<'\n';
		}
	}
	else
	{
		cout<<"-1\n";
	}
	
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:26:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   26 |  while(pq.size()>=k)
      |        ~~~~~~~~~^~~
nicegift.cpp:17:12: warning: unused variable 'a' [-Wunused-variable]
   17 |  int n,k,i,a,x,noel,nonoka,sum=0;
      |            ^
nicegift.cpp:17:21: warning: 'nonoka' may be used uninitialized in this function [-Wmaybe-uninitialized]
   17 |  int n,k,i,a,x,noel,nonoka,sum=0;
      |                     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 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 0 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 0 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 24 ms 3944 KB n=50000
12 Correct 22 ms 3688 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 364 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 0 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 24 ms 3944 KB n=50000
12 Correct 22 ms 3688 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 364 KB n=973
17 Correct 1 ms 364 KB n=989
18 Correct 1 ms 364 KB n=563
19 Correct 1 ms 364 KB n=592
20 Correct 1 ms 364 KB n=938
21 Correct 1 ms 364 KB n=747
22 Correct 1 ms 364 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 571 ms 69948 KB n=1000000
2 Correct 338 ms 38844 KB n=666666
3 Correct 198 ms 21204 KB n=400000
4 Correct 129 ms 13944 KB n=285714
5 Correct 10 ms 1136 KB n=20000
6 Correct 82 ms 8672 KB n=181818
7 Correct 4 ms 752 KB n=10000
8 Correct 4 ms 620 KB n=6666
9 Correct 2 ms 492 KB n=4000
10 Correct 4 ms 620 KB n=2857
11 Correct 1 ms 492 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 0 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 24 ms 3944 KB n=50000
12 Correct 22 ms 3688 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 364 KB n=973
17 Correct 1 ms 364 KB n=989
18 Correct 1 ms 364 KB n=563
19 Correct 1 ms 364 KB n=592
20 Correct 1 ms 364 KB n=938
21 Correct 1 ms 364 KB n=747
22 Correct 1 ms 364 KB n=991
23 Correct 571 ms 69948 KB n=1000000
24 Correct 338 ms 38844 KB n=666666
25 Correct 198 ms 21204 KB n=400000
26 Correct 129 ms 13944 KB n=285714
27 Correct 10 ms 1136 KB n=20000
28 Correct 82 ms 8672 KB n=181818
29 Correct 4 ms 752 KB n=10000
30 Correct 4 ms 620 KB n=6666
31 Correct 2 ms 492 KB n=4000
32 Correct 4 ms 620 KB n=2857
33 Correct 1 ms 492 KB n=2000
34 Correct 17 ms 2412 KB n=23514
35 Correct 16 ms 2540 KB n=23514
36 Correct 2 ms 492 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 44 ms 5604 KB n=100000
39 Correct 43 ms 5604 KB n=100000
40 Correct 1 ms 364 KB n=10
41 Correct 1 ms 364 KB n=100
42 Correct 4 ms 492 KB n=1000
43 Correct 713 ms 85924 KB n=1000000
44 Correct 1189 ms 89212 KB n=1000000
45 Correct 741 ms 55796 KB n=666666
46 Correct 427 ms 31484 KB n=400000
47 Correct 11 ms 1132 KB n=2336
48 Correct 657 ms 49176 KB n=285714
49 Correct 584 ms 41812 KB n=181818
50 Correct 29 ms 2920 KB n=40000
51 Correct 15 ms 1644 KB n=20000
52 Correct 9 ms 1136 KB n=10000
53 Correct 60 ms 4492 KB n=6666
54 Correct 6 ms 748 KB n=4000
55 Correct 224 ms 16236 KB n=2857
56 Correct 6 ms 620 KB n=2000