Skip to content

Commit af19d17

Browse files
authored
Merge pull request #276 from kbokis/37b-1-cauldron
37b-cauldron-and-shroompath solutions
2 parents 12e15a2 + f003d92 commit af19d17

22 files changed

+2168
-14
lines changed

_data/contests/37-PDP.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ cauldron:
5252
statement_pdf_url: "https://drive.google.com/file/d/1tFvY_3m4KCz4ldE3vyLLsidE-PYt1hQs/view"
5353
statement_md: true
5454
testcases_url: ""
55-
solution: false
56-
solution_author: ""
57-
codes_in_git: false
58-
solution_tags: []
55+
solution: true
56+
solution_author: "Κωνσταντίνος Μποκής"
57+
codes_in_git: true
58+
solution_tags: [sorting, greedy]
5959
on_judge: false
6060

6161
shroompath:
@@ -64,10 +64,10 @@ shroompath:
6464
statement_pdf_url: "https://drive.google.com/file/d/1tFvY_3m4KCz4ldE3vyLLsidE-PYt1hQs/view"
6565
statement_md: true
6666
testcases_url: ""
67-
solution: false
68-
solution_author: ""
69-
codes_in_git: false
70-
solution_tags: []
67+
solution: true
68+
solution_author: "Κωνσταντίνος Μποκής"
69+
codes_in_git: true
70+
solution_tags: [greedy, modulo, binary counting]
7171
on_judge: false
7272

7373
mergegame:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
TASK(
2+
name = "cauldron",
3+
test_count = 33,
4+
files_dir = "testdata/37-PDP/cauldron/",
5+
input_file = "cauldron.in",
6+
output_file = "cauldron.out",
7+
time_limit = 1,
8+
mem_limit = 64,
9+
solutions = [
10+
SOLUTION(
11+
name = "cauldron_brute",
12+
source = "cauldron_brute.cc",
13+
passes_up_to = 9,
14+
lang = "c++",
15+
),
16+
SOLUTION(
17+
name = "cauldron_brute_recurse",
18+
source = "cauldron_brute_recurse.cc",
19+
passes_up_to = 9,
20+
lang = "c++",
21+
),
22+
SOLUTION(
23+
name = "cauldron_subtask2",
24+
source = "cauldron_subtask2.cc",
25+
passes_only = [3,8,10,11,12,13,14,15,17,19,23,27,31],
26+
lang = "c++",
27+
),
28+
SOLUTION(
29+
name = "cauldron_subtask3",
30+
source = "cauldron_subtask3.cc",
31+
passes_only = [3,8,10,11,12,13,14,15,16,17,18,19,20,21,23,27,31],
32+
lang = "c++",
33+
),
34+
SOLUTION(
35+
name = "cauldron_correct",
36+
source = "cauldron_correct.cc",
37+
passes_all,
38+
lang = "c++",
39+
),
40+
]
41+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <cstdio>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
8+
int main(){
9+
#ifdef CONTEST
10+
freopen("cauldron.in","r",stdin);
11+
freopen("cauldron.out","w",stdout);
12+
#endif
13+
long t, N, K, c;
14+
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
15+
vector<long> w(N);
16+
ll ans = 0;
17+
for(auto& x:w)
18+
scanf("%ld",&x);
19+
if(N<=20){
20+
for(long s=0,m=(1L<<N);s<m;s++){
21+
long Krem = K;//πόσο μαγικό νερό παραμένει στο καζάνι
22+
ll test = 0;
23+
for(int i=0;i<N;i++){
24+
if((s&(1L<<i)) && Krem>=w[i]){
25+
test += w[i] + c;
26+
Krem -= w[i];
27+
}
28+
}
29+
test += Krem;
30+
ans = max(ans,test);
31+
}
32+
}
33+
printf("%lld\n",ans);
34+
return 0;
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <cstdio>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
typedef long long ll;
6+
7+
long t, N, K, c;
8+
long w[20];
9+
ll ans;
10+
11+
void calc(long Krem,int i,ll csum=0){//Krem=μαγικό νερο στο καζάνι, csum=κέρδος από τα c
12+
if(i==N){
13+
ans = max(ans, K + csum);
14+
return;
15+
}
16+
calc(Krem,i+1,csum);//αν δεν πάρουμε το i
17+
if(Krem>=w[i])//έχουμε αρκετό μαγικό νερό;
18+
calc(Krem-w[i],i+1,csum+c);//αν πάρουμε το i
19+
}
20+
21+
int main(){
22+
#ifdef CONTEST
23+
freopen("cauldron.in","r",stdin);
24+
freopen("cauldron.out","w",stdout);
25+
#endif
26+
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
27+
if(t==1){
28+
for(int i=0;i<N;i++)
29+
scanf("%ld",&w[i]);
30+
calc(K,0);
31+
}
32+
printf("%lld\n",ans);
33+
return 0;
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <cstdio>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
8+
int main(){
9+
#ifdef CONTEST
10+
freopen("cauldron.in","r",stdin);
11+
freopen("cauldron.out","w",stdout);
12+
#endif
13+
long t, N, K, c;
14+
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
15+
vector<long> w(N);
16+
ll ans = K;
17+
for(auto& x:w)
18+
scanf("%ld",&x);
19+
if(c>0){
20+
sort(w.begin(),w.end());
21+
long Krem = K;//πόσο μαγικό νερό παραμένει στο καζάνι
22+
for(auto e:w){
23+
if(e<=Krem){
24+
ans += c;
25+
Krem -= e;
26+
} else break;
27+
}
28+
}
29+
printf("%lld\n",ans);
30+
return 0;
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <cstdio>
2+
3+
int main(){
4+
#ifdef CONTEST
5+
freopen("cauldron.in","r",stdin);
6+
freopen("cauldron.out","w",stdout);
7+
#endif
8+
long t, N, K, c;
9+
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
10+
printf("%ld\n",K);
11+
return 0;
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <cstdio>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
typedef long long ll;
6+
7+
int main(){
8+
#ifdef CONTEST
9+
freopen("cauldron.in","r",stdin);
10+
freopen("cauldron.out","w",stdout);
11+
#endif
12+
long t, N, K, c, w0;
13+
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
14+
ll ans = K;
15+
if(t==3){
16+
scanf("%ld",&w0);//διάβασε ποσότητα ζωμού ενός βάζου
17+
if(c>0){
18+
long jars = min(K/w0,N);
19+
ans += (ll)jars*c;
20+
}
21+
}
22+
printf("%lld\n",ans);
23+
return 0;
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
TASK(
2+
name = "shroompath",
3+
test_count = 37,
4+
files_dir = "testdata/37-PDP/shroompath/",
5+
input_file = "shroompath.in",
6+
output_file = "shroompath.out",
7+
time_limit = 1,
8+
mem_limit = 64,
9+
solutions = [
10+
SOLUTION(
11+
name = "shroom_brute_recursion",
12+
source = "shroom_brute1.cc",
13+
passes_up_to = 10,
14+
lang = "c++",
15+
),
16+
SOLUTION(
17+
name = "shroom_brute_loop",
18+
source = "shroom_brute2.cc",
19+
passes_up_to = 10,
20+
lang = "c++",
21+
),
22+
SOLUTION(
23+
name = "shroom_only_a",
24+
source = "shroom_only_a.cc",
25+
passes_only = [1,3,5,8,9,11,12,13,14,15,16,17,25,29,30,31,35,36,37],
26+
lang = "c++",
27+
),
28+
SOLUTION(
29+
name = "shroom_only_b",
30+
source = "shroom_only_b.cc",
31+
passes_only = [2,4,6,7,10,18,19,20,21,22,23,24,26,27,28,32,33,34],
32+
lang = "c++",
33+
),
34+
SOLUTION(
35+
name = "shroom_solution1",
36+
source = "shroom_solution1.cc",
37+
passes_all,
38+
lang = "c++",
39+
),
40+
SOLUTION(
41+
name = "shroom_solution2",
42+
source = "shroom_solution2.cc",
43+
passes_all,
44+
lang = "c++",
45+
),
46+
SOLUTION(
47+
name = "shroom_solution3",
48+
source = "shroom_solution3_math.cc",
49+
passes_all,
50+
lang = "c++",
51+
),
52+
]
53+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int t,S,X,Y;
7+
long ans = 1000000013;
8+
vector<char> Z;
9+
10+
const char shrooms[] = "ab";//επιτρεπτοί χαρακτήρες
11+
void add_length_w(vector<char>& str,int pos){
12+
//υπολόγισε όλους τους συνδυασμούς ξεκινώντας από τη θέση pos
13+
if(pos == str.size()){//καλύφθηκε το επιθυμητό μήκος
14+
Z.insert(Z.end(),str.begin(),str.end());
15+
return;
16+
}
17+
for(int i=0;shrooms[i]!=0;i++){
18+
str[pos] = shrooms[i];
19+
add_length_w(str,pos+1);
20+
}
21+
}
22+
23+
int main(){
24+
#ifdef CONTEST
25+
freopen("shroompath.in","r",stdin);
26+
freopen("shroompath.out","w",stdout);
27+
#endif
28+
scanf("%d%d%d%d",&t,&S,&X,&Y);
29+
int A = (X>0) ? (S+X-1)/X : -1;
30+
int B = (Y>0) ? (S+Y-1)/Y : -1;
31+
for(int w=1;w<=max(A,B);w++){
32+
vector<char> str(w);
33+
add_length_w(str,0);
34+
}
35+
if(A>0){
36+
vector<char> f(A,'a');
37+
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
38+
ans = min(ans,pos+A);
39+
}
40+
if(B>0){
41+
vector<char> f(B,'b');
42+
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
43+
ans = min(ans,pos+B);
44+
}
45+
printf("%ld\n",ans);
46+
return 0;
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int t,S,X,Y;
7+
long ans = 1000000000;
8+
vector<char> Z;
9+
10+
void add_length_w(int w){
11+
for(int i=0;i < (1<<w);i++)//1<<w == 2^w
12+
for(int j=w-1;j>=0;j--)
13+
Z.push_back((i & (1<<j))?'b':'a');
14+
}
15+
16+
int main(){
17+
#ifdef CONTEST
18+
freopen("shroompath.in","r",stdin);
19+
freopen("shroompath.out","w",stdout);
20+
#endif
21+
scanf("%d%d%d%d",&t,&S,&X,&Y);
22+
int A = (X>0) ? (S+X-1)/X : -1;
23+
int B = (Y>0) ? (S+Y-1)/Y : -1;
24+
for(int w=1;w<=max(A,B);w++)
25+
add_length_w(w);
26+
27+
if(X>0){
28+
vector<char> f(A,'a');
29+
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
30+
ans = min(ans,pos+A);
31+
}
32+
if(Y>0){
33+
vector<char> f(B,'b');
34+
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
35+
ans = min(ans,pos+B);
36+
}
37+
38+
printf("%ld\n",ans);
39+
return 0;
40+
}

0 commit comments

Comments
 (0)