Thanks for your answer, I’ll check with that in mind
Hey guys,
Im getting the first two test case right but im not getting where im going wrong with the last two:
r = int(input())
v = int(input())
work_divided = int(v/r)
total = 0
vault_times = [0] * work_divided
for i in range(v):
c, n = [int(j) for j in input().split()]
time_taken = (10**n)*(5**(c-n))
for i in range(0,len(vault_times)):
if time_taken > vault_times[i]:
vault_times[i] = time_taken
total = sum(vault_times)
print(total)
Your code is not formatted properly, so it is difficult to check. Anyway, I think you may consider whether your code has taken into account the following from the puzzle statement:
Once he finishes one vault, he moves on to the next available vault.
Meaning: they do not divide their work evenly in terms of the number of vaults. Not sure if that was the assumption you made when you calculated the variable work_divided.
All the robbers work at the same time… You have to output the total time the heist takes.
Meaning: you do not have to sum up the times spent by individual robbers. You are requested to output how long the entire heist takes.
Hello,
Isn’t the goal : “You have to output the total time the heist takes.” incorrect ? Wouldn’t it be “You have to output the maximum total time the heist might take.” because one can open a vault on average at number of permutations / 2 ?
Thanks
Not sure what you mean, but the robbers don’t split their work evenly, so I guess averages aren’t relevant.
HI everyone,
It seems that, like many, I get trouble to pass this puzzle (supposed to by a short refreshing one when i started it …).
After failing without takink account of the index rule, I wrote it again stucking to the summary :
<?php
fscanf(STDIN, "%d",
$R
);
fscanf(STDIN, "%d",
$V
);
$sec = [];
$Cmax = 0;
for ($i = 0; $i < $V; $i++)
{
fscanf(STDIN, "%d %d",
$C,
$N
);
$nbChar = $C - $N;
$sec[$i] = pow(10,$N)*pow(5,$nbChar);
if ($C>$Cmax) {
$Cmax = $C;
};
}
$oversizedCombination = pow(10,$Cmax)+1;
$secTot = 0;
$robberVault = [];
// Init the robber task testing if ther is no more robber than vault
for ($i=0;$i<$R;$i++) {
if ($i < $V) {
$robberVault[$i] = $sec[$i];
} else {
$robberVault[$i] = $oversizedCombination;
}
}
// Looping until all vault unlock
// since it the max iteration number is the number of vault (one set to "0" each iteration)
$nextAvailableVault = $R;
$currentIteration = 0;
while ($currentIteration < $V) {
// Finding the robber who end his job this iteration
$secToAdd = min($robberVault);
// decrement second passed to all Robber excep if oversized sec set
// meaning that robber is innocupied
for ($j=0;$j<count($robberVault);$j++){
// If robber is working, decrease by time passed (except for oversized meaning robber lazy)
// It can't be negative since with substract the min value of the table
if ($robberVault[$j] <> $oversizedCombination) {
$robberVault[$j] -= $secToAdd;
}
}
// Affect a new vault to lazies robbers
for ($k=0; $k<count($robberVault); $k++){
// If current robber are negative or zero number meaning his job his done
// but there is still vault to do then affect a new one
if ($robberVault[$k] <= 0 &&
$nextAvailableVault < $V) {
$robberVault[$k]=$sec[$nextAvailableVault];
$nextAvailableVault += 1;
}
// Otherwise, if it's negative or zero number and all vault has been taken
// set it's value to oversized sec number to exclude it
else if ($robberVault[$k] <= 0 && $nextAvailableVault >= $V) {
$robberVault[$k] = $oversizedCombination;
}
// Else, sec number not negative meaning current robber still working on his vault
}
// Adding the total hack time and go trought the next vault
$secTot += $secToAdd;
$currentIteration += 1;
}
/*
OPTIMIZED SOLUTION FOR SHORTEST TIME TO TRY ALL (but not the current problem)
for ($i = 0; $i<$V; $i += $R ) {
$secToAdd = max(array_slice($sec, $i, $R, true));
$secTot += $secToAdd;
}*/
echo($secTot."\n");
?>
And what should happen happened, all tests cases passed but failing validation.
Do you have any clue ?
Best regards,
This line is never reached:
$robberVault[$i] = $oversizedCombination;
because $i is always less than $V in all test cases. And even if there is a test case where the number of robbers is greater than the number of vaults, the “redundant” robbers will have no vault to work on and hence will not affect the answer anyway.
And I think your code fails with this custom case:
2
2
4 0
4 0
The answer should be 625.
Thanks for your test case !
The weakness in the original code was in the loop iteration in the case where all vaults has been cracked before we reach the end of the loop, which happen every time you cracked at least 2 vault in the same iteration (if it’s not the last one, explaining why the third test case success).
Dirty fix : Add a control to set the second to add to 0 if the minimum of the table is equal to the oversized combination. It made the job.
Better fix : Switch to while loop that stop when a counter (increased each time the vault was cracked) reach the total number of vault.
Best fix I guess : Not implementing it that way
For every one who stack with this puzzle on the last “Big Heist” test case,
try not to focus on amount of vaults… sorting vaults by it’s complexity is actually a dead-end. Instead focus on amount of robbers you were given.
@MahmudalKashgari said "Do not sort the times. " and @OlivZed said “Finally, re-re-re-reread the statement and got it ! “index” is the key”. Those 2 things made me realize that I read the specification through the fingers. Index is the key. Much thanks.