#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++) a[i]=1; /// 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!\n", 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--;
assert(DP[i][j][m]);
}
}
sort(cnt.rbegin(), cnt.rend());
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: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]);
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
For every box, the number of cookies in it should be equal to one of the following M numbers: B1, B2, ..., BM |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |