# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
807258 |
2023-08-04T15:17:22 Z |
oscar1f |
Cookies (JOI23_cookies) |
C++17 |
|
801 ms |
1048576 KB |
#include<bits/stdc++.h>
using namespace std;
const int MAX_SOM=15000+5;
using bits=bitset<MAX_SOM>;
int nbPiles,nbPossi,valNouv,somGlob,enCours,minPris,dernPris;
vector<int> possi,listePris;
vector<vector<bits>> estPossi;
bits toutZer;
int nbOccu[MAX_SOM],cumu[MAX_SOM];
set<pair<int,int>> etat,aRemettre;
set<pair<int,int>>::iterator it;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbPiles;
for (int i=0;i<nbPiles;i++) {
cin>>valNouv;
somGlob+=valNouv;
nbOccu[valNouv]++;
etat.insert({-valNouv,i+1});
}
enCours=nbPiles;
for (int i=1;i<MAX_SOM;i++) {
cumu[i]=cumu[i-1]+enCours;
enCours-=nbOccu[i];
//cout<<i<<" : "<<cumu[i]<<endl;
}
cin>>nbPossi;
for (int i=0;i<nbPossi;i++) {
cin>>valNouv;
possi.push_back(valNouv);
}
reverse(possi.begin(),possi.end());
for (int i=nbPossi-1;i>=0;i--) {
estPossi.push_back({});
}
minPris=MAX_SOM;
for (int i=0;i<nbPossi;i++) {
for (int j=0;j<MAX_SOM;j++) { ///=MAX_SOM/possi[i]
estPossi[i].push_back(toutZer);
}
}
estPossi[0][0][0]=true;
for (int i=0;i<nbPossi;i++) {
for (int j=0;j<MAX_SOM;j++) { // A MODIFIER ENSUITE
if (i!=0) {
estPossi[i][j]|=estPossi[i-1][j];
}
if (j!=0) {
estPossi[i][j]|=(estPossi[i][j-1]<<possi[i]);
}
estPossi[i][j]<<=(MAX_SOM-1-cumu[j]);
estPossi[i][j]>>=(MAX_SOM-1-cumu[j]);
if (estPossi[i][j][somGlob] and j<minPris) {
minPris=j;
dernPris=i;
}
//cout<<i<<" "<<j<<" : "<<estPossi[i][j]<<endl;
}
}
if (minPris==MAX_SOM) {
cout<<-1<<endl;
return 0;
}
cout<<minPris<<endl;
while (minPris!=0) {
if (dernPris!=0 and estPossi[dernPris-1][minPris][somGlob]) {
dernPris--;
}
else {
listePris.push_back(possi[dernPris]);
somGlob-=possi[dernPris];
minPris--;
}
}
for (int i:listePris) {
cout<<i<<" ";
for (int j=0;j<i;j++) {
it=etat.begin();
cout<<(*it).second<<" ";
aRemettre.insert({(*it).first+1,(*it).second});
etat.erase(it);
}
for (auto k:aRemettre) {
etat.insert(k);
}
aRemettre.clear();
cout<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
100776 KB |
Output is correct |
2 |
Correct |
34 ms |
30596 KB |
Output is correct |
3 |
Correct |
31 ms |
30672 KB |
Output is correct |
4 |
Correct |
31 ms |
30604 KB |
Output is correct |
5 |
Correct |
63 ms |
73112 KB |
Output is correct |
6 |
Correct |
62 ms |
73132 KB |
Output is correct |
7 |
Correct |
99 ms |
100840 KB |
Output is correct |
8 |
Correct |
36 ms |
30660 KB |
Output is correct |
9 |
Correct |
31 ms |
30596 KB |
Output is correct |
10 |
Runtime error |
801 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
30620 KB |
Output is correct |
2 |
Correct |
39 ms |
30768 KB |
Output is correct |
3 |
Correct |
33 ms |
30696 KB |
Output is correct |
4 |
Correct |
32 ms |
30596 KB |
Output is correct |
5 |
Correct |
32 ms |
30696 KB |
Output is correct |
6 |
Correct |
31 ms |
30648 KB |
Output is correct |
7 |
Correct |
31 ms |
30580 KB |
Output is correct |
8 |
Correct |
32 ms |
30588 KB |
Output is correct |
9 |
Correct |
35 ms |
30664 KB |
Output is correct |
10 |
Correct |
51 ms |
30576 KB |
Output is correct |
11 |
Correct |
31 ms |
30596 KB |
Output is correct |
12 |
Correct |
44 ms |
30612 KB |
Output is correct |
13 |
Correct |
32 ms |
30588 KB |
Output is correct |
14 |
Correct |
33 ms |
30676 KB |
Output is correct |
15 |
Correct |
37 ms |
30616 KB |
Output is correct |
16 |
Correct |
32 ms |
30592 KB |
Output is correct |
17 |
Correct |
31 ms |
30592 KB |
Output is correct |
18 |
Correct |
40 ms |
30664 KB |
Output is correct |
19 |
Correct |
43 ms |
30616 KB |
Output is correct |
20 |
Correct |
41 ms |
30724 KB |
Output is correct |
21 |
Correct |
38 ms |
30692 KB |
Output is correct |
22 |
Correct |
40 ms |
30684 KB |
Output is correct |
23 |
Correct |
31 ms |
30700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
100752 KB |
Output is correct |
2 |
Correct |
33 ms |
30596 KB |
Output is correct |
3 |
Correct |
40 ms |
30672 KB |
Output is correct |
4 |
Correct |
32 ms |
30596 KB |
Output is correct |
5 |
Correct |
32 ms |
30596 KB |
Output is correct |
6 |
Correct |
70 ms |
73204 KB |
Output is correct |
7 |
Correct |
63 ms |
73224 KB |
Output is correct |
8 |
Correct |
96 ms |
100776 KB |
Output is correct |
9 |
Correct |
31 ms |
30596 KB |
Output is correct |
10 |
Correct |
33 ms |
30596 KB |
Output is correct |
11 |
Correct |
32 ms |
30580 KB |
Output is correct |
12 |
Correct |
32 ms |
30572 KB |
Output is correct |
13 |
Correct |
32 ms |
30588 KB |
Output is correct |
14 |
Correct |
33 ms |
30664 KB |
Output is correct |
15 |
Correct |
64 ms |
73160 KB |
Output is correct |
16 |
Correct |
64 ms |
73168 KB |
Output is correct |
17 |
Correct |
105 ms |
100864 KB |
Output is correct |
18 |
Correct |
66 ms |
73192 KB |
Output is correct |
19 |
Correct |
94 ms |
100788 KB |
Output is correct |
20 |
Correct |
101 ms |
100744 KB |
Output is correct |
21 |
Correct |
97 ms |
100732 KB |
Output is correct |
22 |
Correct |
96 ms |
100788 KB |
Output is correct |
23 |
Correct |
95 ms |
100776 KB |
Output is correct |
24 |
Correct |
94 ms |
100756 KB |
Output is correct |
25 |
Correct |
101 ms |
100700 KB |
Output is correct |
26 |
Correct |
96 ms |
100848 KB |
Output is correct |
27 |
Correct |
97 ms |
100780 KB |
Output is correct |
28 |
Correct |
157 ms |
156080 KB |
Output is correct |
29 |
Correct |
95 ms |
100764 KB |
Output is correct |
30 |
Correct |
97 ms |
100760 KB |
Output is correct |
31 |
Correct |
187 ms |
183588 KB |
Output is correct |
32 |
Correct |
142 ms |
128368 KB |
Output is correct |
33 |
Correct |
130 ms |
128476 KB |
Output is correct |
34 |
Correct |
138 ms |
128360 KB |
Output is correct |
35 |
Correct |
275 ms |
266480 KB |
Output is correct |
36 |
Correct |
423 ms |
404464 KB |
Output is correct |
37 |
Correct |
75 ms |
73084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
100776 KB |
Output is correct |
2 |
Correct |
34 ms |
30596 KB |
Output is correct |
3 |
Correct |
31 ms |
30672 KB |
Output is correct |
4 |
Correct |
31 ms |
30604 KB |
Output is correct |
5 |
Correct |
63 ms |
73112 KB |
Output is correct |
6 |
Correct |
62 ms |
73132 KB |
Output is correct |
7 |
Correct |
99 ms |
100840 KB |
Output is correct |
8 |
Correct |
36 ms |
30660 KB |
Output is correct |
9 |
Correct |
31 ms |
30596 KB |
Output is correct |
10 |
Runtime error |
801 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
100776 KB |
Output is correct |
2 |
Correct |
34 ms |
30596 KB |
Output is correct |
3 |
Correct |
31 ms |
30672 KB |
Output is correct |
4 |
Correct |
31 ms |
30604 KB |
Output is correct |
5 |
Correct |
63 ms |
73112 KB |
Output is correct |
6 |
Correct |
62 ms |
73132 KB |
Output is correct |
7 |
Correct |
99 ms |
100840 KB |
Output is correct |
8 |
Correct |
36 ms |
30660 KB |
Output is correct |
9 |
Correct |
31 ms |
30596 KB |
Output is correct |
10 |
Runtime error |
801 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
100776 KB |
Output is correct |
2 |
Correct |
34 ms |
30596 KB |
Output is correct |
3 |
Correct |
31 ms |
30672 KB |
Output is correct |
4 |
Correct |
31 ms |
30604 KB |
Output is correct |
5 |
Correct |
63 ms |
73112 KB |
Output is correct |
6 |
Correct |
62 ms |
73132 KB |
Output is correct |
7 |
Correct |
99 ms |
100840 KB |
Output is correct |
8 |
Correct |
36 ms |
30660 KB |
Output is correct |
9 |
Correct |
31 ms |
30596 KB |
Output is correct |
10 |
Runtime error |
801 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |