답안 #511074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511074 2022-01-15T05:31:07 Z Mazaalai Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 8684 KB
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LLA(x) x.rbegin(),x.rend()
#define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n";
#define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n';
using namespace std;
using PII = pair <int, int>;
int n, k;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	cin >> n >> k;
	vector <PII> nums;
	vector <vector <int> > ans;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		nums.pb({x, i});
	}
	nums.pb({0, 0});
	// int dbg = 0;
	while(1) {
		sort(LLA(nums));
		if (nums[0].ff == 0) break;
		int num = nums[0].ff, nx = nums[k-1].ff;
		// int cur = max(1, num - nx);
		int cur = 1;
		vector <int> curAns(1, cur); 
		for (int i = 0; i < k; i++) {
			nums[i].ff-=cur;
			curAns.pb(nums[i].ss);
		}
		ans.pb(curAns);
		// printPII(nums);
		// if (dbg++==10) break;
	}
	for (int i = 0; i < n; i++) {
		if (nums[i].ff < 0) {
			cout << "-1\n";
			return 0;
		}
	}
	cout << ans.size() << '\n';
	for (auto el : ans) {
		print(el);
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:29:7: warning: unused variable 'num' [-Wunused-variable]
   29 |   int num = nums[0].ff, nx = nums[k-1].ff;
      |       ^~~
nicegift.cpp:29:25: warning: unused variable 'nx' [-Wunused-variable]
   29 |   int num = nums[0].ff, nx = nums[k-1].ff;
      |                         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 256 KB n=3
3 Incorrect 0 ms 204 KB Taken too much stones from the heap
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 256 KB n=3
3 Incorrect 0 ms 204 KB Taken too much stones from the heap
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 256 KB n=3
3 Incorrect 0 ms 204 KB Taken too much stones from the heap
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2066 ms 8684 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 256 KB n=3
3 Incorrect 0 ms 204 KB Taken too much stones from the heap
4 Halted 0 ms 0 KB -