# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829262 | Hanksburger | Cookies (JOI23_cookies) | C++17 | 1091 ms | 24712 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > dp[505][505];
vector<int> pre[505][505], tmp;
int b[505];
vector<pair<int, int> > operation(vector<pair<int, int> > x, int val)
{
if (x.size()<val)
{
vector<pair<int, int> > useless;
return useless;
}
tmp.clear();
for (int i=0; i<val; i++)
{
if (!x[i].first)
{
vector<pair<int, int> > useless;
return useless;
}
x[i].first--;
tmp.push_back(x[i].second);
}
sort(x.begin(), x.end(), greater<pair<int, int> >());
return x;
}
vector<pair<int, int> > compare(vector<pair<int, int> > x, vector<pair<int, int> > y)
{
if (x.empty())
return y;
if (y.empty())
return x;
for (int i=0; i<x.size(); i++)
{
if (x[i].first<y[i].first)
return x;
else if (x[i].first>y[i].first)
return y;
}
return x;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, sum=0;
cin >> n;
for (int i=0; i<n; i++)
{
int x;
cin >> x;
dp[0][0].push_back({x, i+1});
sum+=x;
}
cin >> m;
for (int i=1; i<=m; i++)
cin >> b[i];
sort(b+1, b+m+1);
for (int i=1; i<=sum; i++)
{
for (int j=1; j<=sum; j++)
{
for (int k=1; k<=m; k++)
{
if (i<b[k])
break;
vector<pair<int, int> > res=compare(dp[i][j], operation(dp[i-b[k]][j-1], b[k]));
if (res!=dp[i][j])
{
dp[i][j]=res;
pre[i][j]=tmp;
}
}
if (i==sum && dp[i][j].size())
{
cout << j << '\n';
int ind1=sum, ind2=j;
while (ind2)
{
cout << pre[ind1][ind2].size() << ' ';
for (int val:pre[ind1][ind2])
cout << val << ' ';
cout << '\n';
ind1-=pre[ind1][ind2].size();
ind2--;
}
return 0;
}
}
}
cout << -1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |