Task: | Robotti |
Sender: | zfoil |
Submission time: | 2024-11-06 23:22:38 +0200 |
Language: | C |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 30 |
#2 | ACCEPTED | 70 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2 | details |
#2 | ACCEPTED | 0.00 s | 1, 2 | details |
#3 | ACCEPTED | 0.00 s | 1, 2 | details |
#4 | ACCEPTED | 0.00 s | 1, 2 | details |
#5 | ACCEPTED | 0.00 s | 1, 2 | details |
#6 | ACCEPTED | 0.00 s | 1, 2 | details |
#7 | ACCEPTED | 0.00 s | 1, 2 | details |
#8 | ACCEPTED | 0.00 s | 1, 2 | details |
#9 | ACCEPTED | 0.00 s | 1, 2 | details |
#10 | ACCEPTED | 0.00 s | 1, 2 | details |
#11 | ACCEPTED | 0.00 s | 1, 2 | details |
#12 | ACCEPTED | 0.00 s | 2 | details |
#13 | ACCEPTED | 0.00 s | 2 | details |
#14 | ACCEPTED | 0.00 s | 2 | details |
#15 | ACCEPTED | 0.00 s | 2 | details |
#16 | ACCEPTED | 0.00 s | 2 | details |
#17 | ACCEPTED | 0.00 s | 2 | details |
#18 | ACCEPTED | 0.01 s | 2 | details |
#19 | ACCEPTED | 0.01 s | 2 | details |
#20 | ACCEPTED | 0.01 s | 2 | details |
#21 | ACCEPTED | 0.00 s | 2 | details |
#22 | ACCEPTED | 0.00 s | 2 | details |
#23 | ACCEPTED | 0.02 s | 2 | details |
#24 | ACCEPTED | 0.02 s | 2 | details |
Compiler report
input/code.c: In function 'main': input/code.c:119:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result] 119 | scanf("%d", &number_of_rooms); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ input/code.c:121:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result] 121 | scanf("%s", room_data); | ^~~~~~~~~~~~~~~~~~~~~~
Code
#include <stdio.h> #include <stdlib.h> typedef struct Dll_node Dll_node; struct Dll_node { int distance_to_next_coin; Dll_node *left_node; Dll_node *right_node; }; int skip_to_first_coin(char **room_data_pointer, int *number_of_rooms) { while (**room_data_pointer != '*' && **room_data_pointer != 'R') { (*room_data_pointer)++; (*number_of_rooms)--; if (*number_of_rooms < 0) return -1; } return 0; } void parse_rooms(char *room_data, int number_of_rooms, Dll_node *previous_dll_node, Dll_node **robot_node) { int i, distance_to_next_coin = 1; Dll_node *tmp_dll_node; *robot_node = previous_dll_node; for (i = 1; i < number_of_rooms; i++) { if (room_data[i] == '*' || room_data[i] == 'R') { previous_dll_node->distance_to_next_coin = distance_to_next_coin; tmp_dll_node = (Dll_node*)malloc(sizeof(Dll_node)); previous_dll_node->right_node = tmp_dll_node; previous_dll_node = tmp_dll_node; distance_to_next_coin = 1; if (room_data[i] == 'R') { *robot_node = tmp_dll_node; } } else { distance_to_next_coin++; } } previous_dll_node->right_node = NULL; previous_dll_node->distance_to_next_coin = 4000000; } void add_left_nodes(Dll_node *dll_nodes) { Dll_node *dll_node = dll_nodes; while (dll_node->right_node != NULL) { dll_node->right_node->left_node = dll_node; dll_node = dll_node->right_node; } } void delete_dll_node(Dll_node *dll_node) { if (dll_node->left_node == NULL) { dll_node->right_node->left_node = NULL; } else if (dll_node->right_node == NULL) { dll_node->left_node->right_node = NULL; dll_node->left_node->distance_to_next_coin += dll_node->distance_to_next_coin; } else { dll_node->left_node->right_node = dll_node->right_node; dll_node->left_node->distance_to_next_coin += dll_node->distance_to_next_coin; dll_node->right_node->left_node = dll_node->left_node; } free(dll_node); } void move_robot_left(Dll_node **robot, int* coins, int* steps) { Dll_node *tmp_dll_node; *steps += (*robot)->left_node->distance_to_next_coin; (*coins)++; tmp_dll_node = *robot; *robot = (*robot)->left_node; delete_dll_node(tmp_dll_node); } void move_robot_right(Dll_node **robot, int* coins, int* steps) { Dll_node *tmp_dll_node; *steps += (*robot)->distance_to_next_coin; (*coins)++; tmp_dll_node = *robot; *robot = (*robot)->right_node; delete_dll_node(tmp_dll_node); } void move_robot(Dll_node *robot, int* steps, int* coins) { while (1) { if (robot->left_node == NULL && robot->right_node == NULL) break; if (robot->left_node == NULL) { move_robot_right(&robot, coins, steps); } else if (robot->right_node == NULL) { move_robot_left(&robot, coins, steps); } else { if (robot->distance_to_next_coin == robot->left_node->distance_to_next_coin) { break; } else if (robot->distance_to_next_coin > robot->left_node->distance_to_next_coin) { move_robot_left(&robot, coins, steps); } else { move_robot_right(&robot, coins, steps); } } } } int main(void) { int number_of_rooms, steps = 0, coins = 0, found_any_coin; char *room_data; Dll_node *dll_nodes, *robot; scanf("%d", &number_of_rooms); room_data = (char*)malloc(sizeof(char) * number_of_rooms); scanf("%s", room_data); found_any_coin = skip_to_first_coin(&room_data, &number_of_rooms); if (found_any_coin == -1) { printf("0 0"); return 0; } dll_nodes = (Dll_node*)malloc(number_of_rooms * sizeof(Dll_node)); dll_nodes->left_node = NULL; parse_rooms(room_data, number_of_rooms, dll_nodes, &robot); add_left_nodes(dll_nodes); move_robot(robot, &steps, &coins); printf("%d %d", steps, coins); return 0; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1 R |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 ...R...... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 **.R...*** |
correct output |
---|
12 5 |
user output |
---|
12 5 |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 ***R****** |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 5
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 R................................ |
correct output |
---|
947 9 |
user output |
---|
947 9 |
Test 6
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ................................. |
correct output |
---|
886 9 |
user output |
---|
886 9 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 .....*..*....**..**..*......*.... |
correct output |
---|
1287 400 |
user output |
---|
1287 400 |
Test 8
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ************.*****************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 9
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ******************************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 10
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 R*****************************... |
correct output |
---|
999 999 |
user output |
---|
999 999 |
Test 11
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ******************************... |
correct output |
---|
999 999 |
user output |
---|
999 999 |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
10000 .......**........*...........*... |
correct output |
---|
10971 999 |
user output |
---|
10971 999 |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
10000 *..*....*......*.....*..*........ |
correct output |
---|
9999 999 |
user output |
---|
9999 999 |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
10000 *.*.*...**.*...*....**.**.**..... |
correct output |
---|
18766 5000 |
user output |
---|
18766 5000 |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
10000 R*****************************... |
correct output |
---|
9999 9999 |
user output |
---|
9999 9999 |
Test 16
Group: 2
Verdict: ACCEPTED
input |
---|
10000 ******************************... |
correct output |
---|
9999 9999 |
user output |
---|
9999 9999 |
Test 17
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ................................. |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 18
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ................................. |
correct output |
---|
299934 10000 |
user output |
---|
299934 10000 |
Test 19
Group: 2
Verdict: ACCEPTED
input |
---|
200000 **.***....**..**.....***.*..*.... |
correct output |
---|
299998 100000 |
user output |
---|
299998 100000 |
Test 20
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ******************************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 21
Group: 2
Verdict: ACCEPTED
input |
---|
200000 R................................ |
correct output |
---|
133765 3 |
user output |
---|
133765 3 |
Test 22
Group: 2
Verdict: ACCEPTED
input |
---|
200000 R................................ |
correct output |
---|
199982 5000 |
user output |
---|
199982 5000 |
Test 23
Group: 2
Verdict: ACCEPTED
input |
---|
200000 R*****************************... |
correct output |
---|
199999 199999 |
user output |
---|
199999 199999 |
Test 24
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ******************************... |
correct output |
---|
199999 199999 |
user output |
---|
199999 199999 |