답안 #1029748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029748 2024-07-21T09:04:33 Z Unforgettablepl Cookies (JOI23_cookies) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

const int INF = 1e12;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<pair<int,int>> arr(n);
	int tot = 0;
	for(int i=0;i<n;i++){cin>>arr[i].first;tot+=arr[i].first;arr[i].second=i+1;}
	vector<int> limits(tot+1,INF);
	sort(arr.rbegin(),arr.rend());
	auto carr = arr;
	vector<int> cookies = {-1};
	while(arr[0].first){
		for(int j=0;j<n;j++){
			if(arr[j].first==0)break;
			arr[j].first--;
			cookies.emplace_back(arr[j].second);
		}
	}
	for(int i=1;i<=tot;i++){
		vector<bool> present(n+1);
		for(int j=i+1;j<=tot;j++){
			if(present[cookies[j]]){
				limits[i]=j-i-1;
				break;
			}
			present[cookies[j]]=true;
		}
		limits[i]=min(limits[i],tot-i);
	}
	int m;
	cin >> m;
	vector<int> weights(m);
	for(int&i:weights)cin>>i;
	if(tot%weights[0]){
		cout << "-1\n";
		return 0;
	}
	bool works = true;
	for(int i=1;i<=tot;i+=weights[0]){
		vector<bool> present(n+1);
		for(int j=i;j<i+weights[0];j++){
			if(present[j]){
				works = false;
			}
			present[j]=true;
		}
	}
	if(!works){
		cout << "-1\n";
		return 0;
	}
	cout << tot/weights[0] << '\n';
	for(int i=1;i<=tot;i+=weights[0]){
		cout << weights[0] << ' ';
		for(int j=i;j<i+weights[0];j++){
			cout << cookies[j] << ' ';
		}
		cout << '\n';
	}
	return 0;
	vector<pair<int,int>> DP(tot+1,{INF,0});
	DP[0].first = 0;
	int curr_limit = tot;
	for(int i=0;i<=tot;i++){
		curr_limit=min(curr_limit,limits[i]);
		for(int j=0;j<m;j++){
			if(weights[j]>curr_limit)break;
			DP[i+weights[j]]=min(DP[i+weights[j]],{DP[i].first+1,i});
		}
	}
	if(DP[tot].first>=INF){
		cout << "-1\n";
		return 0;
	}
	cout << DP[tot].first << '\n';
	int curr = tot;
	for(int i=1;i<=DP[tot].first;i++){
		int nxt = DP[curr].second;
		cout << curr-nxt << ' ';
		for(int j=curr;j>nxt;j--){
			cout << cookies[j] << ' ';
		}
		cout << '\n';
		curr = nxt;
	}
	assert(curr==0);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 424 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Runtime error 0 ms 604 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -