# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789228 |
2023-07-21T08:21:07 Z |
반딧불(#10041) |
Cookies (JOI23_cookies) |
C++17 |
|
1 ms |
340 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k, s;
int a[3002], b[3002];
int lim[3002];
bool DP[502][502][502]; /// DP[i][j][m]: i��°�� ���� j, �ִ밡 m�� �ǵ��� ���� �� �ִ°�?
int ansI = 1e9, ansJ = -1, ansM = -1;
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%d", &a[i]);
s = accumulate(a+1, a+n+1, 0);
scanf("%d", &k);
for(int i=1; i<=k; i++) scanf("%d", &b[i]);
reverse(b+1, b+k+1);
for(int i=1; i<=s; i++){
for(int j=1; j<=s; j++){
lim[i] += min(a[j], i);
}
}
DP[0][0][1] = 1;
for(int i=0; i<s; i++){
for(int j=i; j<=s; j++){
for(int m=1; m<=k; m++){
if(!DP[i][j][m]) continue;
// printf("cnt %d sum %d max %d possible!", i, j, b[m]);
if(j==s){
if(ansI > i){
ansI = i, ansJ = j, ansM = m;
goto answer;
}
}
if(m<k) DP[i][j][m+1] = 1; /// �������� �ѱ��
if(j+b[m]<=lim[i+1]) DP[i+1][j+b[m]][m] = 1; /// �ֱ�
}
}
}
answer:
if(ansI == 1e9){
puts("-1");
return 0;
}
vector<int> cnt;
int i = ansI, j = ansJ, m = ansM;
while(i){
if(DP[i][j][m-1]) m--;
else{
cnt.push_back(b[m]);
j -= b[m], i--;
}
}
vector<vector<int> > ans;
for(int p: cnt){
vector<pair<int, int> > vec;
for(int i=1; i<=n; i++) vec.push_back(make_pair(a[i], i));
sort(vec.rbegin(), vec.rend());
ans.push_back(vector<int>());
for(int i=0; i<p; i++) ans.back().push_back(vec[i].second), a[vec[i].second]--;
}
printf("%d\n", (int)ans.size());
for(auto p: ans){
printf("%d ", (int)p.size());
for(auto x: p) printf("%d ", x);
puts("");
}
}
Compilation message
cookies.cpp: In function 'int main()':
cookies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
cookies.cpp:16:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | for(int i=1; i<=n; i++) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
cookies.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
cookies.cpp:19:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | for(int i=1; i<=k; i++) scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |