Pagini recente »
Cod sursă (job #249377)
|
Istoria paginii runda/2020-05-09-clasa-5-concurs
|
Istoria paginii runda/lasm_26_03_2020_11
|
Istoria paginii runda/2020-05-09-clasa-5-concurs
|
Cod sursă (job #672332)
Cod sursă (job
#672332)
// #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;
long long bestTime;
int state;
void initProcess();
void status_1();
void status_2();
long long simulate_finish();
void status_5();
void initProcess(){
currentTime = minerals = 0;
currentSCV = 1;
state = 1;
bestTime = L;
}
void status_1() {
if (currentTime > L) {
state = 6;
}
bestTime = min(bestTime, simulate_finish());
state = 2;
}
void status_2() {
if (costNewSCV <= minerals) {
minerals -= costNewSCV;
state = 5;
return;
}
long long deltaTime = (costNewSCV - minerals + currentSCV * productionSCV - 1)
/ (currentSCV * productionSCV);
currentTime += deltaTime;
minerals += deltaTime * currentSCV * productionSCV;
if (currentTime > L) {
state = 6;
} else {
minerals -= costNewSCV;
state = 5;
}
}
long long simulate_finish() {
if (goalProduction <= minerals) {
return currentTime;
}
long long deltaTime = (goalProduction - minerals + currentSCV * productionSCV - 1)
/ (currentSCV * productionSCV);
if (currentTime + deltaTime > L) {
return L;
} else {
return currentTime + deltaTime;
}
}
void status_5() {
minerals += currentSCV * productionSCV * timeNewSCV;
currentTime += timeNewSCV;
if (currentTime > L) {
state = 6;
} else {
currentSCV++;
state = 1;
}
}
int main(){
fin >> costNewSCV >> timeNewSCV >> productionSCV >> goalProduction;
initProcess();
int iter = L;
while (currentTime < bestTime && state != 6 && iter) {
// cerr << state << " " << currentTime << " " << bestTime << endl;
switch (state) {
case 1:
status_1();
break;
case 2:
status_2();
break;
case 5:
status_5();
break;
}
iter--;
}
fout << bestTime << "\n";
return 0;
}