Pagini recente »
Istoria paginii runda/2020-01-23-clasa-7-tema-18-optionala/clasament
|
Istoria paginii runda/concurs9_04_12_2020/clasament
|
Cod sursă (job #639217)
|
Istoria paginii runda/2024-10-08-clasa-6-tema-11
|
Cod sursă (job #672329)
Cod sursă (job
#672329)
// #include <bits/stdc++.h>
#include <fstream>
// #include <iostream>
#define L 5e6 + 5
#define FAIL L + 1
// #define fin cin
// #define fout cout
using namespace std;
ifstream fin("scv.in");
ofstream fout("scv.out");
long long costNewSCV, timeNewSCV, productionSCV, goalProduction;
long long currentTime, currentSCV, minerals, totalSCV;
bool success;
void startProcess(long long numberOfSCV);
bool status_1();
bool status_2();
bool status_3();
bool status_4();
bool status_5();
bool status_6();
void startProcess(long long numberOfSCV){
totalSCV = numberOfSCV;
currentTime = minerals = 0;
currentSCV = 1;
if (!status_1()) {
currentTime = FAIL;
}
}
bool status_1(){
if (currentSCV < totalSCV) {
return status_2();
} else {
return status_3();
}
}
bool status_2(){
if (costNewSCV <= minerals) {
minerals -= costNewSCV;
return status_5();
}
int deltaTime = (costNewSCV - minerals + currentSCV * productionSCV - 1) / (currentSCV * productionSCV);
currentTime += deltaTime;
minerals += deltaTime * currentSCV * productionSCV;
if (currentTime > L) {
return status_6();
} else {
minerals -= costNewSCV;
return status_5();
}
}
bool status_3(){
if (goalProduction <= minerals) {
return status_4();
}
int deltaTime = (goalProduction - minerals + currentSCV * productionSCV - 1) / (currentSCV * productionSCV);
currentTime += deltaTime;
minerals += deltaTime * currentSCV * productionSCV;
if (currentTime > L) {
return status_6();
} else {
return status_4();
}
}
bool status_4(){
return true;
}
bool status_5(){
minerals += currentSCV * productionSCV * timeNewSCV;
currentTime += timeNewSCV;
if (currentTime > L)
return status_6();
else{
currentSCV++;
return status_1();
}
}
bool status_6(){
return false;
}
int main(){
long long le, ri, mid1, mid2, best, time1, time2;
fin >> costNewSCV >> timeNewSCV >> productionSCV >> goalProduction;
/**
startProcess(3);
cout << currentTime << "\n";
**/
/**/
le = best = 1;
///ri = L;
ri = goalProduction + 1;
while (le <= ri){
mid1 = le + (ri - le) / 3;
mid2 = le + 2 * (ri - le) / 3;
///cout << "Process was started for " << mid1 << ".\n";
startProcess(mid1);
time1 = currentTime;
///cout << "CurrentTime is " << time1 << ".\n\n";
///cout << "Process was started for " << mid2 << ".\n";
startProcess(mid2);
time2 = currentTime;
///cout << "CurrentTime is " << time2 << ".\n\n";
if (time1 < time2){
best = time1;
ri = mid2 - 1;
}
else{
best = time2;
le = mid1 + 1;
}
}
fout << best << "\n";
/**/
return 0;
}