#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 1.5e4 + 42;
vector<int> boite;
vector<bitset<N>> dp[N];
int n, m, a[N], sz[N], prefix[N];
void remonter(int i, int j, int sum) {
if(sum == 0)
return;
if(dp[i-1][j][sum - sz[j]]) {
boite.push_back(-sz[j]);
remonter(i-1, j, sum - sz[j]);
} else {
remonter(i, j+1, sum);
}
}
void printSol() {
vector<int> id[N];
for(int i = 0; i < n; i++)
for(int j = 0; j < a[i]; j++)
id[j].push_back(i+1);
queue<int> ids;
for(int i = 0; i < N; i++)
for(int j : id[i])
ids.push(j);
sort(boite.begin(), boite.end());
int t = (int)boite.size(), sum = 0;
cout << t << '\n';
for(int i = 0; i < t; i++) {
boite[i] = -boite[i];
sum += boite[i];
if(sum > prefix[i+1]) {
cout << "wtf\n";
return;
}
for(int j = 0; j < boite[i]; j++) {
cout << ids.front() << ' ';
ids.pop();
}
cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i];
for(int j = 0; j < N; j++)
prefix[j] += min(j, a[i]);
}
cin >> m;
dp[0].resize(m);
dp[0][m-1] = true;
for(int i = 0; i < m; i++)
cin >> sz[i];
int sum = prefix[N-1];
for(int i = 0; i <= sum; i++) {
for(int j = m-1; j >= 0; j--)
if(i * sz[j] <= sum) {
dp[i+1].resize(j+1);
j = 0;
}
for(int j = m-1; j >= 0; j--)
if(i * sz[j] <= sum) {
dp[i][j] <<= (N-prefix[i]-1);
dp[i][j] >>= (N-prefix[i]-1);
//cout << i << ' ' << j << ' ' << dp[i][j] << ' ' << dp[i][j][sum] << ' ' << sum << ' ' << prefix[i] << '\n';
if(dp[i][j][sum]) {
remonter(i, j, sum);
printSol();
return 0;
}
if(j > 0)
dp[i][j-1] |= dp[i][j];
if((i+1) * sz[j] <= sum)
dp[i+1][j] |= (dp[i][j] << sz[j]);
}
}
cout << -1 << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Too many cookies.. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Too many cookies.. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Too many cookies.. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Too many cookies.. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Too many cookies.. |
2 |
Halted |
0 ms |
0 KB |
- |