Pagini recente » Cod sursa (job #1775627) | Cod sursa (job #1715264) | Cod sursa (job #384188) | Cod sursa (job #3279068) | Cod sursa (job #3265487)
#define BRANZA_SOLVER__BULWARK_OPEN {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
#include <limits.h>
#include <errno.h>
#include <assert.h>
#include <stdbool.h>
#define BRANZA_SOLVER__CONVENTIONS__INPUT_FILE "branza.in"
#define BRANZA_SOLVER__CONVENTIONS__OUTPUT_FILE "branza.out"
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_N_ITS_MIN_VALUE UINT64_C(1)
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_N_ITS_MAX_VALUE UINT64_C(100000)
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_S_ITS_MIN_VALUE UINT64_C(1)
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_S_ITS_MAX_VALUE UINT64_C(100)
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_T_ITS_MIN_VALUE UINT64_C(1)
#define BRANZA_SOLVER__RESTRICTIONS__INTEGER_T_ITS_MAX_VALUE UINT64_C(100000)
#define BRANZA_SOLVER__RESTRICTIONS__CHEESE_COST_ITS_MIN_VALUE UINT64_C(1)
#define BRANZA_SOLVER__RESTRICTIONS__CHEESE_COST_ITS_MAX_VALUE UINT64_C(10000000)
#define BRANZA_SOLVER__RESTRICTIONS__CHEESE_DEMAND_ITS_MIN_VALUE UINT64_C(1)
#define BRANZA_SOLVER__RESTRICTIONS__CHEESE_DEMAND_ITS_MAX_VALUE UINT64_C(10000000)
#define BRANZA_SOLVER__TWEAKS__LINE_BUFFER_ITS_SIZE UINT64_C(64)
#define BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE 0
#define BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY 1
#define BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_SIZE_TYPE 2
#define BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_INT_TYPE 3
#define BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT 4
#define BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INVALID_INPUT 5
struct branza_solver__data_up__program_state {
char * branza_solver__field__line_buffer_itself;
size_t branza_solver__field__line_buffer_its_size;
int branza_solver__field__line_buffer_its_isize;
FILE * branza_solver__field__input_file_itself;
FILE * branza_solver__field__output_file_itself;
size_t branza_solver__field__integer_n_itself;
uint64_t branza_solver__field__integer_s_itself;
size_t branza_solver__field__integer_t_itself;
uint64_t * branza_solver__field__sequence_c_itself;
uint64_t * branza_solver__field__sequence_p_itself;
size_t * branza_solver__field__deque_min_cost_itself;
uint64_t branza_solver__field__answer_itself;
};
#define BRANZA_SOLVER__BULWARK_CLOSE }
int branza_solver__acquire_resources_up_front (struct branza_solver__data_up__program_state * * receptacle) {
/* Step is introduce local variables, be done with it. */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
struct branza_solver__data_up__program_state * program_state_itself = NULL;
char * line_buffer_itself = NULL;
size_t line_buffer_its_size = 0;
int line_buffer_its_isize = 0;
FILE * input_file_itself = NULL;
FILE *output_file_itself = NULL;
size_t integer_n_itself = 0;
uint64_t integer_s_itself = 0;
size_t integer_t_itself = 0;
uint64_t * sequence_c_itself = NULL;
uint64_t * sequence_p_itself = NULL;
size_t * deque_min_cost_itself = NULL;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is malloc() acquire the program state thing itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
size_t number_of_bytes = 0;
void * pointer_itself = NULL;
number_of_bytes = sizeof(struct branza_solver__data_up__program_state);
pointer_itself = malloc(number_of_bytes);
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY;
}
else {
program_state_itself = pointer_itself;
}
}
}
/* Step is malloc() acquire the line buffer itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
uint64_t amount_itself = 0;
size_t number_of_bytes = 0;
void * pointer_itself = NULL;
amount_itself = BRANZA_SOLVER__TWEAKS__LINE_BUFFER_ITS_SIZE;
if (SIZE_MAX < amount_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_SIZE_TYPE;
}
else {
if (((unsigned) INT_MAX) < amount_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_INT_TYPE;
}
else {
number_of_bytes = ((size_t) amount_itself);
pointer_itself = malloc(number_of_bytes);
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY;
}
else {
line_buffer_itself = pointer_itself;
line_buffer_its_size = number_of_bytes;
line_buffer_its_isize = ((int) number_of_bytes);
}
}
}
}
}
/* Step is fopen() acquire the input file itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
const char * file_path = NULL;
FILE * pointer_itself = NULL;
file_path = BRANZA_SOLVER__CONVENTIONS__INPUT_FILE;
pointer_itself = fopen(file_path, "r");
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
input_file_itself = pointer_itself;
}
}
}
/* Step is fopen() acquire the output file itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
const char * file_path = NULL;
FILE * pointer_itself = NULL;
file_path = BRANZA_SOLVER__CONVENTIONS__OUTPUT_FILE;
pointer_itself = fopen(file_path, "w");
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
output_file_itself = pointer_itself;
}
}
}
/* Step is fgets(), fscanf() acquire values n, s, t themselves. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
char * str = NULL;
int size = 0;
FILE * stream = NULL;
char * pointer_itself = NULL;
size_t line_its_length = 0;
size_t value_for_n_itself = 0;
uint64_t value_for_s_itself = 0;
size_t value_for_t_itself = 0;
int status_of_sorts = 0;
str = line_buffer_itself;
size = line_buffer_its_isize;
stream = input_file_itself;
pointer_itself = fgets(str, size, stream);
if ((NULL == pointer_itself) || (pointer_itself != str)) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
line_its_length = strlen(str);
if ((line_its_length < 1) || ('\n' != str[line_its_length - 1])) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
str[line_its_length - 1] = '\0';
line_its_length -= 1;
status_of_sorts = sscanf(str, "%zu"
"%" SCNu64
"%zu",
&value_for_n_itself,
&value_for_s_itself,
&value_for_t_itself);
if (3 != status_of_sorts) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
size_t min_value_for_n_itself = 0;
size_t max_value_for_n_itself = 0;
uint64_t min_value_for_s_itself = 0;
uint64_t max_value_for_s_itself = 0;
size_t min_value_for_t_itself = 0;
size_t max_value_for_t_itself = 0;
min_value_for_n_itself = ((size_t) BRANZA_SOLVER__RESTRICTIONS__INTEGER_N_ITS_MIN_VALUE);
max_value_for_n_itself = ((size_t) BRANZA_SOLVER__RESTRICTIONS__INTEGER_N_ITS_MAX_VALUE);
min_value_for_s_itself = BRANZA_SOLVER__RESTRICTIONS__INTEGER_S_ITS_MIN_VALUE;
max_value_for_s_itself = BRANZA_SOLVER__RESTRICTIONS__INTEGER_S_ITS_MAX_VALUE;
min_value_for_t_itself = ((size_t) BRANZA_SOLVER__RESTRICTIONS__INTEGER_T_ITS_MIN_VALUE);
max_value_for_t_itself = ((size_t) BRANZA_SOLVER__RESTRICTIONS__INTEGER_T_ITS_MAX_VALUE);
if ((value_for_n_itself < min_value_for_n_itself) || (max_value_for_n_itself < value_for_n_itself) ||
(value_for_s_itself < min_value_for_s_itself) || (max_value_for_s_itself < value_for_s_itself) ||
(value_for_t_itself < min_value_for_t_itself) || (max_value_for_t_itself < value_for_t_itself) ) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
integer_n_itself = value_for_n_itself;
integer_s_itself = value_for_s_itself;
integer_t_itself = value_for_t_itself;
}
}
}
}
}
}
/* Step is malloc() acquire the sequence c itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
size_t number_of_elements = 0;
size_t element_byte_size = 0;
size_t number_of_bytes = 0;
void * pointer_itself = NULL;
number_of_elements = integer_n_itself;
element_byte_size = sizeof(uint64_t);
if ((SIZE_MAX / element_byte_size) < number_of_elements) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_SIZE_TYPE;
}
else {
number_of_bytes = number_of_elements * element_byte_size;
pointer_itself = malloc(number_of_bytes);
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY;
}
else {
sequence_c_itself = pointer_itself;
}
}
}
}
/* Step is malloc() acquire the sequence p itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
size_t number_of_elements = 0;
size_t element_byte_size = 0;
size_t number_of_bytes = 0;
void * pointer_itself = NULL;
number_of_elements = integer_n_itself;
element_byte_size = sizeof(uint64_t);
if ((SIZE_MAX / element_byte_size) < number_of_elements) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_SIZE_TYPE;
}
else {
number_of_bytes = number_of_elements * element_byte_size;
pointer_itself = malloc(number_of_bytes);
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY;
}
else {
sequence_p_itself = pointer_itself;
}
}
}
}
/* Step is malloc() acquire the min cost deque itself. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
size_t number_of_elements = 0;
size_t element_byte_size = 0;
size_t number_of_bytes = 0;
void * pointer_itself = NULL;
number_of_elements = integer_n_itself;
element_byte_size = sizeof(size_t);
if ((SIZE_MAX / element_byte_size) < number_of_elements) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__WEE_SIZE_TYPE;
}
else {
number_of_bytes = number_of_elements * element_byte_size;
pointer_itself = malloc(number_of_bytes);
if (NULL == pointer_itself) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__OUT_OF_MEMORY;
}
else {
deque_min_cost_itself = pointer_itself;
}
}
}
}
/* Step is pass the baton, already. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
program_state_itself->branza_solver__field__line_buffer_itself = line_buffer_itself;
program_state_itself->branza_solver__field__line_buffer_its_size = line_buffer_its_size;
program_state_itself->branza_solver__field__line_buffer_its_isize = line_buffer_its_isize;
program_state_itself->branza_solver__field__input_file_itself = input_file_itself;
program_state_itself->branza_solver__field__output_file_itself = output_file_itself;
program_state_itself->branza_solver__field__integer_n_itself = integer_n_itself;
program_state_itself->branza_solver__field__integer_s_itself = integer_s_itself;
program_state_itself->branza_solver__field__integer_t_itself = integer_t_itself;
program_state_itself->branza_solver__field__sequence_c_itself = sequence_c_itself;
program_state_itself->branza_solver__field__sequence_p_itself = sequence_p_itself;
program_state_itself->branza_solver__field__deque_min_cost_itself = deque_min_cost_itself;
program_state_itself->branza_solver__field__answer_itself = 0;
*receptacle = program_state_itself;
}
else {
if (NULL != deque_min_cost_itself) {
free(deque_min_cost_itself);
deque_min_cost_itself = NULL;
}
if (NULL != sequence_p_itself) {
free(sequence_p_itself);
sequence_p_itself = NULL;
}
if (NULL != sequence_c_itself) {
free(sequence_c_itself);
sequence_c_itself = NULL;
}
if (NULL != output_file_itself) {
int status_of_sorts = 0;
status_of_sorts = fclose(output_file_itself);
output_file_itself = NULL;
(void) status_of_sorts;
}
if (NULL != input_file_itself) {
int status_of_sorts = 0;
status_of_sorts = fclose(input_file_itself);
input_file_itself = NULL;
(void) status_of_sorts;
}
if (NULL != line_buffer_itself) {
free(line_buffer_itself);
line_buffer_itself = NULL;
line_buffer_its_size = 0;
line_buffer_its_isize = 0;
}
if (NULL != program_state_itself) {
free(program_state_itself);
program_state_itself = NULL;
}
}
return exit_status_itself;
}
}
int branza_solver__read_remaining_input_at_once (struct branza_solver__data_up__program_state * program_state_itself) {
/* Step is introduce local variables, let's go! */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is read sequences c and p, altogether. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
uint64_t min_unit_cost = 0;
uint64_t max_unit_cost = 0;
uint64_t min_demand = 0;
uint64_t max_demand = 0;
uint64_t * sequence_c_itself = NULL;
uint64_t * sequence_p_itself = NULL;
FILE * input_file_itself = NULL;
char * line_buffer_itself = NULL;
size_t line_buffer_its_size = 0;
int line_buffer_its_isize = 0;
size_t integer_n_itself = 0;
size_t current_index_itself = 0;
char * get_ptr = NULL;
size_t line_its_length = 0;
uint64_t current_unit_cost = 0;
uint64_t current_demand = 0;
int status_of_sorts = 0;
min_unit_cost = BRANZA_SOLVER__RESTRICTIONS__CHEESE_COST_ITS_MIN_VALUE;
max_unit_cost = BRANZA_SOLVER__RESTRICTIONS__CHEESE_COST_ITS_MAX_VALUE;
min_demand = BRANZA_SOLVER__RESTRICTIONS__CHEESE_DEMAND_ITS_MIN_VALUE;
max_demand = BRANZA_SOLVER__RESTRICTIONS__CHEESE_DEMAND_ITS_MAX_VALUE;
sequence_c_itself = program_state_itself->branza_solver__field__sequence_c_itself;
sequence_p_itself = program_state_itself->branza_solver__field__sequence_p_itself;
input_file_itself = program_state_itself->branza_solver__field__input_file_itself;
line_buffer_itself = program_state_itself->branza_solver__field__line_buffer_itself;
line_buffer_its_size = program_state_itself->branza_solver__field__line_buffer_its_size;
line_buffer_its_isize = program_state_itself->branza_solver__field__line_buffer_its_isize;
integer_n_itself = program_state_itself->branza_solver__field__integer_n_itself;
current_index_itself = 0;
while ((BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) && (current_index_itself < integer_n_itself)) {
get_ptr = fgets(line_buffer_itself, line_buffer_its_isize, input_file_itself);
if ((get_ptr == NULL) || (get_ptr != line_buffer_itself)) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
line_its_length = strlen(line_buffer_itself);
if ((line_its_length < 1) || (line_buffer_its_size <= line_its_length) || ('\n' != line_buffer_itself[line_its_length - 1])) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;
}
else {
line_buffer_itself[line_its_length - 1] = '\0';
line_its_length -= 1;
status_of_sorts = sscanf(line_buffer_itself, "%" SCNu64
"%" SCNu64,
¤t_unit_cost,
¤t_demand);
if (2 != status_of_sorts) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;
}
else {
if ((current_unit_cost < min_unit_cost) || (max_unit_cost < current_unit_cost) ||
(current_demand < min_demand) || (max_demand < current_demand)) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;
}
else {
sequence_c_itself[current_index_itself] = current_unit_cost;
sequence_p_itself[current_index_itself] = current_demand;
current_index_itself += 1;
}
}
}
}
}
}
}
/* Step is pass the baton, go, go, go! */ {
return exit_status_itself;
}
}
int branza_solver__solve_the_problem_already (struct branza_solver__data_up__program_state * program_state_itself) {
/* Step is introduce local variables. */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is move the sliding window, solving it. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
/* Step is introduce local variables, why not. */ {
BRANZA_SOLVER__BULWARK_CLOSE
uint64_t total_cost_itself = 0;
size_t integer_n_itself = 0;
uint64_t integer_s_itself = 0;
size_t integer_t_itself = 0;
uint64_t * sequence_c_itself = NULL;
uint64_t * sequence_p_itself = NULL;
size_t * deque_min_cost_itself = NULL;
size_t deque_min_cost_its_begin_position = 0;
size_t deque_min_cost_its_end_position = 0;
size_t sliding_window_its_end_position = 0;
size_t index_first = 0;
size_t index_last = 0;
uint64_t cost_last = 0;
size_t index_best = 0;
uint64_t cost_best = 0;
size_t index_prev = 0;
uint64_t cost_prev = 0;
uint64_t instant_demand = 0;
uint64_t instant_cost = 0;
bool more_could_be_dropped_off = false;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is initialize local variables, now. */ {
total_cost_itself = 0;
integer_n_itself = program_state_itself->branza_solver__field__integer_n_itself;
integer_s_itself = program_state_itself->branza_solver__field__integer_s_itself;
integer_t_itself = program_state_itself->branza_solver__field__integer_t_itself;
sequence_c_itself = program_state_itself->branza_solver__field__sequence_c_itself;
sequence_p_itself = program_state_itself->branza_solver__field__sequence_p_itself;
deque_min_cost_itself = program_state_itself->branza_solver__field__deque_min_cost_itself;
}
/* Step is put up the initial window. */ {
deque_min_cost_its_begin_position = 0;
deque_min_cost_its_end_position = 1;
deque_min_cost_itself[0] = 0;
sliding_window_its_end_position = 1;
}
/* Step is take the minimum in the window. */ {
index_last = sliding_window_its_end_position - 1;
index_best = deque_min_cost_itself[deque_min_cost_its_begin_position];
cost_best = sequence_c_itself[index_best] + (index_last - index_best) * integer_s_itself;
instant_demand = sequence_p_itself[index_last];
instant_cost = cost_best * instant_demand;
total_cost_itself += instant_cost;
}
/* Step is run the long loop, already, come now. */ {
while (sliding_window_its_end_position < integer_n_itself) {
/* Step is advance the sliding window itself. */ {
/* Step is step forward, the end position. */ {
sliding_window_its_end_position += 1;
index_first = deque_min_cost_itself[deque_min_cost_its_begin_position];
if (integer_t_itself < (sliding_window_its_end_position - index_first)) {
deque_min_cost_its_begin_position += 1;
}
}
/* Step is loop maintain the deque itself. */ {
index_last = sliding_window_its_end_position - 1;
cost_last = sequence_c_itself[index_last];
do {
index_prev = deque_min_cost_itself[deque_min_cost_its_end_position - 1];
cost_prev = sequence_c_itself[index_prev] + (index_last - index_prev) * integer_s_itself;
if (cost_last <= cost_prev) {
deque_min_cost_its_end_position -= 1;
more_could_be_dropped_off = (deque_min_cost_its_begin_position < deque_min_cost_its_end_position);
}
else {
more_could_be_dropped_off = false;
}
}
while (more_could_be_dropped_off);
}
/* Step is poke last index, top of the deque. */ {
index_last = sliding_window_its_end_position - 1;
deque_min_cost_its_end_position += 1;
deque_min_cost_itself[deque_min_cost_its_end_position - 1] = index_last;
}
}
/* Step is take minimum value in sliding window. */ {
index_last = sliding_window_its_end_position - 1;
index_best = deque_min_cost_itself[deque_min_cost_its_begin_position];
cost_best = sequence_c_itself[index_best] + (index_last - index_best) * integer_s_itself;
instant_demand = sequence_p_itself[index_last];
instant_cost = cost_best * instant_demand;
total_cost_itself += instant_cost;
}
}
}
/* Step is publish the result, party over. */ {
program_state_itself->branza_solver__field__answer_itself = total_cost_itself;
}
}
}
/* Step is pass the baton, already. */ {
return exit_status_itself;
}
}
int branza_solver__write_the_output_one_fell_swoop (struct branza_solver__data_up__program_state * program_state_itself) {
/* Step is introduce local variables. */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is write the answer, be done with it. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
uint64_t answer_itself = 0;
FILE * output_file_itself = NULL;
char * line_buffer_itself = NULL;
size_t line_buffer_its_size = 0;
int line_buffer_its_isize = 0;
int status_of_sorts = 0;
answer_itself = program_state_itself->branza_solver__field__answer_itself;
output_file_itself = program_state_itself->branza_solver__field__output_file_itself;
line_buffer_itself = program_state_itself->branza_solver__field__line_buffer_itself;
line_buffer_its_size = program_state_itself->branza_solver__field__line_buffer_its_size;
line_buffer_its_isize = program_state_itself->branza_solver__field__line_buffer_its_isize;
status_of_sorts = snprintf(line_buffer_itself, line_buffer_its_size, "%" PRIu64 "\n", answer_itself);
if ((status_of_sorts <= 0) || (line_buffer_its_isize <= status_of_sorts)) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
else {
status_of_sorts = fputs(line_buffer_itself, output_file_itself);
if ((EOF == status_of_sorts) || (status_of_sorts < 0)) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
}
}
}
/* Step is pass the baton, already. */ {
return exit_status_itself;
}
}
int branza_solver__release_resources_down_back (struct branza_solver__data_up__program_state * program_state_itself) {
/* Step is introduce one local variable, why not. */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is memset() zero the answer itself. */ {
program_state_itself->branza_solver__field__answer_itself = 0;
}
/* Step is free() release deque min cost itself. */ {
free(program_state_itself->branza_solver__field__deque_min_cost_itself);
program_state_itself->branza_solver__field__deque_min_cost_itself = NULL;
}
/* Step is free() release sequence p itself. */ {
free(program_state_itself->branza_solver__field__sequence_p_itself);
program_state_itself->branza_solver__field__sequence_p_itself = NULL;
}
/* Step is free() release sequence c itself. */ {
free(program_state_itself->branza_solver__field__sequence_c_itself);
program_state_itself->branza_solver__field__sequence_c_itself = NULL;
}
/* Step is memset() zero values t, s, n. */ {
program_state_itself->branza_solver__field__integer_t_itself = 0;
program_state_itself->branza_solver__field__integer_s_itself = 0;
program_state_itself->branza_solver__field__integer_n_itself = 0;
}
/* Step is fclose() the output file itself. */ {
int status_of_sorts = 0;
status_of_sorts = fclose(program_state_itself->branza_solver__field__output_file_itself);
program_state_itself->branza_solver__field__output_file_itself = NULL;
if (0 != status_of_sorts) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
}
/* Step is fclose() the input file itself. */ {
int status_of_sorts = 0;
status_of_sorts = fclose(program_state_itself->branza_solver__field__input_file_itself);
program_state_itself->branza_solver__field__input_file_itself = NULL;
if (0 != status_of_sorts) {
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__NAY_FAILURE__INPUT_OUTPUT;
}
}
/* Step is free() release line buffer itself. */ {
free(program_state_itself->branza_solver__field__line_buffer_itself);
program_state_itself->branza_solver__field__line_buffer_itself = NULL;
program_state_itself->branza_solver__field__line_buffer_its_size = 0;
program_state_itself->branza_solver__field__line_buffer_its_isize = 0;
}
/* Step is free() release the program state itself. */ {
free(program_state_itself);
program_state_itself = NULL;
}
/* Step is pass the baton, already. */ {
return exit_status_itself;
}
}
int main (void) {
/* Step is introduce local variables already. */ {
BRANZA_SOLVER__BULWARK_CLOSE
int exit_status_itself = 0;
struct branza_solver__data_up__program_state * program_state_itself = NULL;
exit_status_itself = BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
BRANZA_SOLVER__BULWARK_OPEN
}
/* Step is acquire all resources, up front. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
struct branza_solver__data_up__program_state * pointer_itself = NULL;
int status_of_sorts = 0;
status_of_sorts = branza_solver__acquire_resources_up_front(&pointer_itself);
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
assert(NULL != pointer_itself);
exit_status_itself = status_of_sorts;
}
else {
assert(NULL != pointer_itself);
program_state_itself = pointer_itself;
}
}
}
/* Step is read remaining input, at once. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
int status_of_sorts = 0;
status_of_sorts = branza_solver__read_remaining_input_at_once(program_state_itself);
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
exit_status_itself = status_of_sorts;
}
}
}
/* Step is solve the problem, already. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
int status_of_sorts = 0;
status_of_sorts = branza_solver__solve_the_problem_already(program_state_itself);
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
exit_status_itself = status_of_sorts;
}
}
}
/* Step is write the output, one fell swoop. */ {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
int status_of_sorts = 0;
status_of_sorts = branza_solver__write_the_output_one_fell_swoop(program_state_itself);
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
exit_status_itself = status_of_sorts;
}
}
}
/* Step is release all resources, down back. */ {
if (NULL != program_state_itself) {
int status_of_sorts = 0;
status_of_sorts = branza_solver__release_resources_down_back(program_state_itself);
program_state_itself = NULL;
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
if (BRANZA_SOLVER__EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
exit_status_itself = status_of_sorts;
}
}
}
}
/* Step is pass the baton. */ {
return exit_status_itself;
}
}