Use long long.
This commit is contained in:
@@ -5,28 +5,28 @@
|
|||||||
// alive. xxx_num denotes the count as the question described.
|
// alive. xxx_num denotes the count as the question described.
|
||||||
|
|
||||||
int ans[200] = {0};
|
int ans[200] = {0};
|
||||||
int dead_nodes_num[105] = {0};
|
long long dead_nodes_num[105] = {0};
|
||||||
int total_dead_nodes = 0;
|
int total_dead_nodes = 0;
|
||||||
int target_nodes_num[105] = {0};
|
long long target_nodes_num[105] = {0};
|
||||||
int total_target_nodes = 0;
|
int total_target_nodes = 0;
|
||||||
|
|
||||||
struct SeveralContinuedDeadNode {
|
struct SeveralContinuedDeadNode {
|
||||||
bool status;
|
bool status;
|
||||||
int length; // Caution that when status == dead and length == 1, the node itself is alive.
|
long long length; // Caution that when status == dead and length == 1, the node itself is alive.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SearchResult {
|
struct SearchResult {
|
||||||
int next_ans_pos; // pos in the ans[] array.
|
int next_ans_pos; // pos in the ans[] array.
|
||||||
int count_in_father_line; // natural count.
|
long long count_in_father_line; // natural count.
|
||||||
};
|
};
|
||||||
|
|
||||||
SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
|
SearchResult find_node(long long target, long long start_num, int next_dead_node_num_ptr,
|
||||||
SeveralContinuedDeadNode *upper_line, int upper_line_segment_count,
|
SeveralContinuedDeadNode *upper_line, long long upper_line_segment_count,
|
||||||
int layer) {
|
int layer) {
|
||||||
int spawned_node_max_num = start_num - 1;
|
long long spawned_node_max_num = start_num - 1;
|
||||||
int segment_count = upper_line_segment_count;
|
long long segment_count = upper_line_segment_count;
|
||||||
SeveralContinuedDeadNode current_line_node[200] = {0};
|
SeveralContinuedDeadNode current_line_node[200] = {0};
|
||||||
int current_line_len = 0;
|
long long current_line_len = 0;
|
||||||
bool all_dead = true;
|
bool all_dead = true;
|
||||||
|
|
||||||
// Spawing all the nodes in current line
|
// Spawing all the nodes in current line
|
||||||
@@ -38,7 +38,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
all_dead = false;
|
all_dead = false;
|
||||||
int total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
|
long long total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
|
||||||
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
|
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
|
||||||
next_dead_node_num_ptr < total_dead_nodes) {
|
next_dead_node_num_ptr < total_dead_nodes) {
|
||||||
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
|
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
|
||||||
@@ -70,7 +70,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
|
|||||||
|
|
||||||
if (target <= spawned_node_max_num) {
|
if (target <= spawned_node_max_num) {
|
||||||
ans[0] = target;
|
ans[0] = target;
|
||||||
int natural_pos = -1, num = start_num - 1;
|
long long natural_pos = -1, num = start_num - 1;
|
||||||
for (int i = 0; i < current_line_len; i++) {
|
for (int i = 0; i < current_line_len; i++) {
|
||||||
if (current_line_node[i].status == DEAD) {
|
if (current_line_node[i].status == DEAD) {
|
||||||
natural_pos += current_line_node[i].length;
|
natural_pos += current_line_node[i].length;
|
||||||
@@ -102,7 +102,7 @@ SearchResult find_node(int target, int start_num, int next_dead_node_num_ptr,
|
|||||||
return SearchResult{1, -1};
|
return SearchResult{1, -1};
|
||||||
}
|
}
|
||||||
|
|
||||||
int natural_count = -1, num = start_num - 1;
|
long long natural_count = -1, num = start_num - 1;
|
||||||
for (int i = 0; i < current_line_len; i++) {
|
for (int i = 0; i < current_line_len; i++) {
|
||||||
natural_count += current_line_node[i].length;
|
natural_count += current_line_node[i].length;
|
||||||
if (current_line_node[i].status == ALIVE || current_line_node[i].length == 1) {
|
if (current_line_node[i].status == ALIVE || current_line_node[i].length == 1) {
|
||||||
@@ -131,10 +131,10 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int current_target = 0;
|
long long current_target = 0;
|
||||||
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
|
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
|
||||||
for (int i = 0; i < total_target_nodes; i++) {
|
for (int i = 0; i < total_target_nodes; i++) {
|
||||||
scanf("%d", ¤t_target);
|
scanf("%lld", ¤t_target);
|
||||||
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
|
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
|
||||||
if (result.count_in_father_line == -1) {
|
if (result.count_in_father_line == -1) {
|
||||||
printf("0\n");
|
printf("0\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user