Pagini recente »
Istoria paginii utilizator/mihaigusa
|
Monitorul de evaluare
|
Monitorul de evaluare
|
Atașamentele paginii Clasament oji_9_2019
|
Cod sursă (job #672328)
Cod sursă (job
#672328)
// #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;
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(){
///cout << "STATUS_2 was triggered!\n";
if (costNewSCV <= minerals) {
minerals -= costNewSCV;
status_5();
return;
}
int 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(){
///cout << "STATUS_3 was triggered!\n";
if (goalProduction <= minerals) {
status_4();
return;
}
int 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;
}