Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions _data/contests/37-PDP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ cauldron:
statement_pdf_url: "https://drive.google.com/file/d/1tFvY_3m4KCz4ldE3vyLLsidE-PYt1hQs/view"
statement_md: true
testcases_url: ""
solution: false
solution_author: ""
codes_in_git: false
solution_tags: []
solution: true
solution_author: "Κωνσταντίνος Μποκής"
codes_in_git: true
solution_tags: [sorting, greedy]
on_judge: false

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

mergegame:
Expand Down
41 changes: 41 additions & 0 deletions _includes/source_code/code/37-PDP/cauldron/TASK
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
TASK(
name = "cauldron",
test_count = 33,
files_dir = "testdata/37-PDP/cauldron/",
input_file = "cauldron.in",
output_file = "cauldron.out",
time_limit = 1,
mem_limit = 64,
solutions = [
SOLUTION(
name = "cauldron_brute",
source = "cauldron_brute.cc",
passes_up_to = 9,
lang = "c++",
),
SOLUTION(
name = "cauldron_brute_recurse",
source = "cauldron_brute_recurse.cc",
passes_up_to = 9,
lang = "c++",
),
SOLUTION(
name = "cauldron_subtask2",
source = "cauldron_subtask2.cc",
passes_only = [3,8,10,11,12,13,14,15,17,19,23,27,31],
lang = "c++",
),
SOLUTION(
name = "cauldron_subtask3",
source = "cauldron_subtask3.cc",
passes_only = [3,8,10,11,12,13,14,15,16,17,18,19,20,21,23,27,31],
lang = "c++",
),
SOLUTION(
name = "cauldron_correct",
source = "cauldron_correct.cc",
passes_all,
lang = "c++",
),
]
)
35 changes: 35 additions & 0 deletions _includes/source_code/code/37-PDP/cauldron/cauldron_brute.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

int main(){
#ifdef CONTEST
freopen("cauldron.in","r",stdin);
freopen("cauldron.out","w",stdout);
#endif
long t, N, K, c;
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
vector<long> w(N);
ll ans = 0;
for(auto& x:w)
scanf("%ld",&x);
if(N<=20){
for(long s=0,m=(1L<<N);s<m;s++){
long Krem = K;//πόσο μαγικό νερό παραμένει στο καζάνι
ll test = 0;
for(int i=0;i<N;i++){
if((s&(1L<<i)) && Krem>=w[i]){
test += w[i] + c;
Krem -= w[i];
}
}
test += Krem;
ans = max(ans,test);
}
}
printf("%lld\n",ans);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

long t, N, K, c;
long w[20];
ll ans;

void calc(long Krem,int i,ll csum=0){//Krem=μαγικό νερο στο καζάνι, csum=κέρδος από τα c
if(i==N){
ans = max(ans, K + csum);
return;
}
calc(Krem,i+1,csum);//αν δεν πάρουμε το i
if(Krem>=w[i])//έχουμε αρκετό μαγικό νερό;
calc(Krem-w[i],i+1,csum+c);//αν πάρουμε το i
}

int main(){
#ifdef CONTEST
freopen("cauldron.in","r",stdin);
freopen("cauldron.out","w",stdout);
#endif
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
if(t==1){
for(int i=0;i<N;i++)
scanf("%ld",&w[i]);
calc(K,0);
}
printf("%lld\n",ans);
return 0;
}
31 changes: 31 additions & 0 deletions _includes/source_code/code/37-PDP/cauldron/cauldron_correct.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

int main(){
#ifdef CONTEST
freopen("cauldron.in","r",stdin);
freopen("cauldron.out","w",stdout);
#endif
long t, N, K, c;
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
vector<long> w(N);
ll ans = K;
for(auto& x:w)
scanf("%ld",&x);
if(c>0){
sort(w.begin(),w.end());
long Krem = K;//πόσο μαγικό νερό παραμένει στο καζάνι
for(auto e:w){
if(e<=Krem){
ans += c;
Krem -= e;
} else break;
}
}
printf("%lld\n",ans);
return 0;
}
12 changes: 12 additions & 0 deletions _includes/source_code/code/37-PDP/cauldron/cauldron_subtask2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cstdio>

int main(){
#ifdef CONTEST
freopen("cauldron.in","r",stdin);
freopen("cauldron.out","w",stdout);
#endif
long t, N, K, c;
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
printf("%ld\n",K);
return 0;
}
24 changes: 24 additions & 0 deletions _includes/source_code/code/37-PDP/cauldron/cauldron_subtask3.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

int main(){
#ifdef CONTEST
freopen("cauldron.in","r",stdin);
freopen("cauldron.out","w",stdout);
#endif
long t, N, K, c, w0;
scanf("%ld%ld%ld%ld",&t,&N,&K,&c);
ll ans = K;
if(t==3){
scanf("%ld",&w0);//διάβασε ποσότητα ζωμού ενός βάζου
if(c>0){
long jars = min(K/w0,N);
ans += (ll)jars*c;
}
}
printf("%lld\n",ans);
return 0;
}
53 changes: 53 additions & 0 deletions _includes/source_code/code/37-PDP/shroompath/TASK
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
TASK(
name = "shroompath",
test_count = 37,
files_dir = "testdata/37-PDP/shroompath/",
input_file = "shroompath.in",
output_file = "shroompath.out",
time_limit = 1,
mem_limit = 64,
solutions = [
SOLUTION(
name = "shroom_brute_recursion",
source = "shroom_brute1.cc",
passes_up_to = 10,
lang = "c++",
),
SOLUTION(
name = "shroom_brute_loop",
source = "shroom_brute2.cc",
passes_up_to = 10,
lang = "c++",
),
SOLUTION(
name = "shroom_only_a",
source = "shroom_only_a.cc",
passes_only = [1,3,5,8,9,11,12,13,14,15,16,17,25,29,30,31,35,36,37],
lang = "c++",
),
SOLUTION(
name = "shroom_only_b",
source = "shroom_only_b.cc",
passes_only = [2,4,6,7,10,18,19,20,21,22,23,24,26,27,28,32,33,34],
lang = "c++",
),
SOLUTION(
name = "shroom_solution1",
source = "shroom_solution1.cc",
passes_all,
lang = "c++",
),
SOLUTION(
name = "shroom_solution2",
source = "shroom_solution2.cc",
passes_all,
lang = "c++",
),
SOLUTION(
name = "shroom_solution3",
source = "shroom_solution3_math.cc",
passes_all,
lang = "c++",
),
]
)
47 changes: 47 additions & 0 deletions _includes/source_code/code/37-PDP/shroompath/shroom_brute1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int t,S,X,Y;
long ans = 1000000013;
vector<char> Z;

const char shrooms[] = "ab";//επιτρεπτοί χαρακτήρες
void add_length_w(vector<char>& str,int pos){
//υπολόγισε όλους τους συνδυασμούς ξεκινώντας από τη θέση pos
if(pos == str.size()){//καλύφθηκε το επιθυμητό μήκος
Z.insert(Z.end(),str.begin(),str.end());
return;
}
for(int i=0;shrooms[i]!=0;i++){
str[pos] = shrooms[i];
add_length_w(str,pos+1);
}
}

int main(){
#ifdef CONTEST
freopen("shroompath.in","r",stdin);
freopen("shroompath.out","w",stdout);
#endif
scanf("%d%d%d%d",&t,&S,&X,&Y);
int A = (X>0) ? (S+X-1)/X : -1;
int B = (Y>0) ? (S+Y-1)/Y : -1;
for(int w=1;w<=max(A,B);w++){
vector<char> str(w);
add_length_w(str,0);
}
if(A>0){
vector<char> f(A,'a');
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
ans = min(ans,pos+A);
}
if(B>0){
vector<char> f(B,'b');
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
ans = min(ans,pos+B);
}
printf("%ld\n",ans);
return 0;
}
40 changes: 40 additions & 0 deletions _includes/source_code/code/37-PDP/shroompath/shroom_brute2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int t,S,X,Y;
long ans = 1000000000;
vector<char> Z;

void add_length_w(int w){
for(int i=0;i < (1<<w);i++)//1<<w == 2^w
for(int j=w-1;j>=0;j--)
Z.push_back((i & (1<<j))?'b':'a');
}

int main(){
#ifdef CONTEST
freopen("shroompath.in","r",stdin);
freopen("shroompath.out","w",stdout);
#endif
scanf("%d%d%d%d",&t,&S,&X,&Y);
int A = (X>0) ? (S+X-1)/X : -1;
int B = (Y>0) ? (S+Y-1)/Y : -1;
for(int w=1;w<=max(A,B);w++)
add_length_w(w);

if(X>0){
vector<char> f(A,'a');
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
ans = min(ans,pos+A);
}
if(Y>0){
vector<char> f(B,'b');
long pos = search(Z.begin(), Z.end(), f.begin(), f.end()) - Z.begin();
ans = min(ans,pos+B);
}

printf("%ld\n",ans);
return 0;
}
26 changes: 26 additions & 0 deletions _includes/source_code/code/37-PDP/shroompath/shroom_only_a.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <cstdio>

typedef long long ll;
const ll mod = 1000000007;
long t,S,X,Y;

long calc_a(int A){
ll pow2 = 1;//2^0
ll prev=0;//άθροισμα μανιταριών που προσπεράσαμε στα προηγούμενα μήκη
for(long i=1;;i++){
pow2 = (pow2 * 2) % mod;//2^i
if(A<=2*i-1) return (prev + A) % mod;
prev = (prev + pow2*i) % mod;
}
return -1L;
}

int main(){
#ifdef CONTEST
freopen("shroompath.in","r",stdin);
freopen("shroompath.out","w",stdout);
#endif
scanf("%ld%ld%ld%ld",&t,&S,&X,&Y);
if(X>0)printf("%ld\n",calc_a((S+X-1)/X));
return 0;
}
Loading