Pagini recente »
2024-08-21-clasa-6-tema-2
|
Clasament 2021-04-04-pregatire-osepi1
|
Istoria paginii runda/2021-11-07-clasa-10-2
|
Istoria paginii runda/2024-11-06-clasa-7-tema-8-optional/clasament
|
Cod sursă (job #671782)
Cod sursă (job
#671782)
#include <bits/stdc++.h>
#define L 5e6 + 5
#define FAIL L + 1
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;
inline void startProcess(long long numberOfSCV);
inline void status_1();
inline void status_2();
inline void status_3();
inline void status_4();
inline void status_5();
inline void status_6();
inline void startProcess(long long numberOfSCV){
totalSCV = numberOfSCV;
currentTime = minerals = 0;
currentSCV = 1;
///cout << "PROCESS STARTED!\n";
status_1();
if (!success)
currentTime = FAIL;
}
inline void status_1(){
///cout << "STATUS_1 was triggered!\n";
///cout << "CURRENT_TIME = " << currentTime << "\n";
/**
if (currentTime > 2e5){
cout << "CURRENT_SCV = " << currentSCV << "\n";
cout << "MINERALS = " << minerals << "\n";
}
**/
if (currentSCV < totalSCV)
status_2();
else
status_3();
}
inline void status_2(){
int deltaTime;
///cout << "STATUS_2 was triggered!\n";
deltaTime = (costNewSCV - minerals + currentSCV * productionSCV - 1) / (currentSCV * productionSCV);
currentTime += deltaTime;
minerals += deltaTime * currentSCV * productionSCV;
if (currentTime > L)
status_6();
else{
minerals -= costNewSCV;
status_5();
}
/*
if (currentTime > L){
///cout << "STATUS_2 triggered FAIL!\n";
status_6();
}
else if (minerals < costNewSCV){
minerals = minerals + currentSCV * productionSCV;
currentTime++;
status_2();
}
else{
minerals -= costNewSCV;
status_5();
}
*/
}
inline void status_3(){
int deltaTime;
///cout << "STATUS_3 was triggered!\n";
deltaTime = (goalProduction - minerals + currentSCV * productionSCV - 1) / (currentSCV * productionSCV);
currentTime += deltaTime;
minerals += deltaTime * currentSCV * productionSCV;
if (currentTime > L)
status_6();
else
status_4();
/*
if (currentTime > L){
///cout << "STATUS_3 triggered FAIL!\n";
status_6();
}
else if (minerals < goalProduction){
minerals = minerals + currentSCV * productionSCV;
currentTime++;
status_3();
}
else
status_4();
*/
}
inline void status_4(){
///cout << "SUCCESS!\n";
success = true;
}
inline void status_5(){
//long long i;
//bool failed = false;
///cout << "STATUS_5 was triggered!\n";
minerals += currentSCV * productionSCV * timeNewSCV;
currentTime += timeNewSCV;
if (currentTime > L)
status_6();
else{
currentSCV++;
status_1();
}
/*
for (i = 0; i < timeNewSCV; i++){
if (currentTime > L){
i = timeNewSCV;
failed = true;
}
minerals = minerals + currentSCV * productionSCV;
currentTime++;
}
if (failed){
///cout << "STATUS_5 triggered FAIL!\n";
status_6();
}
else{
currentSCV++;
status_1();
}
*/
}
inline void status_6(){
///cout << "FAIL!\n";
success = 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;
}