Submission #837757

#TimeUsernameProblemLanguageResultExecution timeMemory
837757AntekbCookies (JOI23_cookies)C++17
63 / 100
1131 ms1048576 KiB
#include<bits/stdc++.h> #define st first #define nd second #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define pp pop_back #define mp make_pair using namespace std; using pii = pair<int, int>; using ll = long long; using vi = vector<int>; using vii = vector<pii>; using ld = long double; void debug(){cerr<<"\n";} template<typename H, typename... T> void debug(H h, T... t){ cerr<<h; if(sizeof...(t)){ cerr<<", "; } debug(t...); } #define deb(x...) cerr<<#x<<" = ";debug(x); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=3005; vi par[N][N]; vector<bool> par2[N][N]; int opt[N], tim[N], ile[N], str[N][N]; int main(){ int n, m; cin>>n; vii V(n); int M=0; for(int i=0;i<n; i++){ cin>>V[i].st; M=max(M, V[i].st); for(int j=0; j<V[i].st; j++)ile[j]++; V[i].nd=i+1; } sort(all(V)); int s=0; for(int i=0; i<M; i++){ for(int j=s; j<s+ile[M-i-1]; j++){ tim[j]=i; } s+=ile[M-i-1]; } tim[s]=M; for(int i=1; i<=s; i++){ opt[i]=-1e9; //deb(i, tim[i]); } cin>>m; vi V2(m); for(int &i:V2){ cin>>i; } sort(all(V2)); for(int i=0; i<=s; i++){ for(int j=0; j<=M; j++){ str[i][j]=1e9; } } str[0][0]=0; opt[0]=0; for(int c:V2){ for(int i=c; i<=s; i++){ if(opt[i]<min(opt[i-c]+1, tim[i])){ opt[i]=min(opt[i-c]+1, tim[i]); } for(int j=1; j<=opt[i]; j++){ if(str[i][j]>str[i-c][j-1]){ str[i][j]=str[i-c][j-1]; par[i][j].pb(c); par2[i][j].pb(0); } } for(int j=0; j<=opt[i]; j++){ if(str[i][j]>str[i-c][j]+1){ str[i][j]=str[i-c][j]+1; par[i][j].pb(c); par2[i][j].pb(1); } } } //for(int i=0; i<=s; i++){deb(i, tim[i], opt[i]);} /*cout<<c<<"\n"; for(int i=0; i<=s; i++){ deb(i, opt[i], tim[i]); for(int j=0; j<=opt[i]; j++){ cout<<str[i][j]<<" "; } cout<<"\n"; }*/ } if(opt[s]!=M){ cout<<-1; return 0; } vi siz; int prv=1e9; int j=M; while(s){ //deb(s,j,str[s][j]); //deb(par[s][j].size()); while(par[s][j].back()>prv){ par[s][j].pp(); par2[s][j].pp(); } int jj=par2[s][j].back(); prv=par[s][j].back(); //deb(prv, jj); siz.pb(prv); s-=prv; j-=1-jj; } cout<<siz.size()<<"\n"; //for(int i:siz)cout<<i<<" "; //return 0; priority_queue<pair<int, int> > Q; for(auto &i:V)Q.push(i); for(int j:siz){ cout<<j<<" "; vii todo; for(int i=0; i<j; i++){ assert(Q.size()); todo.pb(Q.top()); Q.pop(); cout<<todo.back().nd<<" "; todo.back().st--; } cout<<"\n"; for(auto i:todo){ if(i.st)Q.push(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...