Submission #1214212

#TimeUsernameProblemLanguageResultExecution timeMemory
1214212salmonCookies (JOI23_cookies)C++20
0 / 100
0 ms584 KiB
#include <bits/stdc++.h> using namespace std; int N; int M; int lst[15100]; int B[15100]; int from[15100]; vector<int> memo[15100]; priority_queue<pair<int,int>> pq; map<vector<int>,pair<int,vector<int> >> mep[16]; 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]); } vector<int> temp; for(int i = 1; i <= N; i++) temp.push_back(lst[i]); sort(temp.begin(),temp.end(),greater<int>()); B[M + 1] = b + 1; mep[b][temp] = {0,{}}; for(int i = b; i > 0; i--){ for(pair<vector<int>,pair<int,vector<int> >> ii : mep[i]){ for(int j = 0; B[j] <= (int)ii.first.size(); j++){ vector<int> temp = ii.first; //printf("%d\n",i); //for(int i : temp) printf("%d ",i); //printf("\n"); for(int k = 0; k < B[j]; k++) temp[k]--; sort(temp.begin(),temp.end(),greater<int>()); while(temp.size() != 0 && temp.back() == 0) temp.pop_back(); if(mep[i - B[j]].find(temp) != mep[i - B[j]].end()){ mep[i - B[j]][temp] = min(mep[i - B[j]][temp], {ii.second.first + 1, ii.first}); } else mep[i - B[j]][temp] = {ii.second.first + 1, ii.first}; } } } int num = mep[0][{}].first; if(num == 0){ printf("-1\n"); } else{ vector<int> temp = {}; int cont = 0; vector<int> bos = {}; for(int i = 0; i < num; i++){ int sum = 0; temp = mep[cont][temp].second; for(int i : temp) sum += i; bos.push_back(sum - cont); cont = sum; } while(!pq.empty()) pq.pop(); for(int i = 1; i <= N; i++) pq.push({lst[i],i}); for(int i : bos){ printf("%d ",i); vector<pair<int,int>> v; for(int j = 0; j < i; j++){ v.push_back(pq.top()); pq.pop(); } for(pair<int,int> ii : v){ if(ii.first != 1){ pq.push({ii.first - 1, ii.second}); } printf("%d ",ii.second); } printf("\n"); } } }

Compilation message (stderr)

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