Submission #1214126

#TimeUsernameProblemLanguageResultExecution timeMemory
1214126salmonCookies (JOI23_cookies)C++20
6 / 100
11 ms5956 KiB
#include <bits/stdc++.h> using namespace std; int N; int M; int lst[15100]; int B[15100]; bitset<3100> memo[15100]; priority_queue<pair<int,int>> pq; int main(){ scanf(" %d",&N); int big = 0; int b = 0; for(int i = 1; i <= N; i++){ scanf(" %d",&lst[i]); big = max(lst[i],big); b += lst[i]; } scanf(" %d",&M); for(int i = 1; i <= M; i++){ scanf(" %d",&B[i]); } B[M + 1] = b + 1; memo[0][0] = 1; for(int i = 1; i <= b; i++){ for(int j = 0; B[j] <= i; j++){ memo[i] |= (memo[i-B[j]]<<1); } } int ans = -1; for(int i = big; i <= b; i++){ if((int)memo[b][i]){ ans = i; break; } } if(ans == -1){ printf("%d\n",ans); } else{ for(int i = 1; i <= N; i++){ pq.push({lst[i],i}); } int pos = b; printf("%d\n",ans); for(int i = ans - 1; i >= 0; i--){ for(int j = 1; j <= M; j++){ if(memo[pos - B[j]][i] ){ pos = pos - B[j]; printf("%d ",B[j]); vector<pair<int,int>> vii; for(int k = 0; k < B[j]; k++){ vii.push_back(pq.top()); pq.pop(); } for(pair<int,int> ii : vii){ if(ii.first != 1){ pq.push({ii.first - 1, ii.second}); } printf("%d ",ii.second); } printf("\n"); break; } } } } }

Compilation message (stderr)

cookies.cpp: In function 'int main()':
cookies.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
cookies.cpp:19:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |                 scanf(" %d",&lst[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~
cookies.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf(" %d",&M);
      |         ~~~~~^~~~~~~~~~
cookies.cpp:27:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |                 scanf(" %d",&B[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...