Submission #829262

#TimeUsernameProblemLanguageResultExecution timeMemory
829262HanksburgerCookies (JOI23_cookies)C++17
0 / 100
1091 ms24712 KiB
#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)

cookies.cpp: In function 'std::vector<std::pair<int, int> > operation(std::vector<std::pair<int, int> >, int)':
cookies.cpp:8:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    8 |     if (x.size()<val)
      |         ~~~~~~~~^~~~
cookies.cpp: In function 'std::vector<std::pair<int, int> > compare(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
cookies.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0; i<x.size(); i++)
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...