답안 #963366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963366 2024-04-14T21:45:58 Z MilosMilutinovic Gift (IZhO18_nicegift) C++14
30 / 100
55 ms 17820 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,k;
int a[2000005];

int main(){
	n=readint(); k=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	set<pii> st;
	for(int i=1;i<=n;i++) if(a[i]>0) st.emplace(a[i],i);
	vector<vector<int>> ans;
	while(!st.empty()){
		if(st.size()<k){
			printf("-1\n");
			return 0;
		}
		ans.pb({});
		for(int i=1;i<=k;i++){
			auto it=prev(st.end());
			ans.back().pb(it->se);
			a[it->se]--;
			st.erase(it);
		}
		for(int i:ans.back()){
			if(a[i]>0) st.emplace(a[i],i);
		}
	}
	printf("%d\n",ans.size());
	for(auto p:ans){
		printf("1 ");
		for(int i=0;i<(int)p.size();i++){
			printf("%d ",p[i]);
		}
		printf("\n");
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:36:15: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if(st.size()<k){
      |      ~~~~~~~~~^~
nicegift.cpp:51:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   51 |  printf("%d\n",ans.size());
      |          ~^    ~~~~~~~~~~
      |           |            |
      |           int          std::vector<std::vector<int> >::size_type {aka long unsigned int}
      |          %ld
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 344 KB n=3
4 Correct 0 ms 344 KB n=4
5 Correct 1 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 344 KB n=3
4 Correct 0 ms 344 KB n=4
5 Correct 1 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 3 ms 940 KB n=8
9 Correct 6 ms 1176 KB n=14
10 Correct 4 ms 920 KB n=11
11 Correct 25 ms 5424 KB n=50000
12 Correct 36 ms 5860 KB n=50000
13 Correct 20 ms 3364 KB n=10
14 Correct 19 ms 3084 KB n=685
15 Correct 25 ms 3344 KB n=623
16 Correct 12 ms 2064 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 344 KB n=3
4 Correct 0 ms 344 KB n=4
5 Correct 1 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 3 ms 940 KB n=8
9 Correct 6 ms 1176 KB n=14
10 Correct 4 ms 920 KB n=11
11 Correct 25 ms 5424 KB n=50000
12 Correct 36 ms 5860 KB n=50000
13 Correct 20 ms 3364 KB n=10
14 Correct 19 ms 3084 KB n=685
15 Correct 25 ms 3344 KB n=623
16 Correct 12 ms 2064 KB n=973
17 Correct 21 ms 2644 KB n=989
18 Correct 10 ms 1116 KB n=563
19 Correct 15 ms 1628 KB n=592
20 Correct 16 ms 1376 KB n=938
21 Correct 13 ms 1376 KB n=747
22 Correct 14 ms 1352 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 17820 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 344 KB n=3
4 Correct 0 ms 344 KB n=4
5 Correct 1 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 3 ms 940 KB n=8
9 Correct 6 ms 1176 KB n=14
10 Correct 4 ms 920 KB n=11
11 Correct 25 ms 5424 KB n=50000
12 Correct 36 ms 5860 KB n=50000
13 Correct 20 ms 3364 KB n=10
14 Correct 19 ms 3084 KB n=685
15 Correct 25 ms 3344 KB n=623
16 Correct 12 ms 2064 KB n=973
17 Correct 21 ms 2644 KB n=989
18 Correct 10 ms 1116 KB n=563
19 Correct 15 ms 1628 KB n=592
20 Correct 16 ms 1376 KB n=938
21 Correct 13 ms 1376 KB n=747
22 Correct 14 ms 1352 KB n=991
23 Incorrect 55 ms 17820 KB Not all heaps are empty in the end
24 Halted 0 ms 0 KB -