Submission #75753813
Source Code Expand
Copy
#include <stdio.h>struct node_s {int value;struct node_s *prev, *next;};int pnext = 0;struct node_s pool[512345];struct node_s* get_node(void) {return &pool[pnext++];}int get_offset(int syuki) {int ans = 1, a = 10, b = 100;while (b > 0) {if (b & 1) ans = (int)((long long)ans * a % syuki);a = (int)((long long)a * a % syuki);b >>= 1;}return ans;}int N;int A[512345];int masu_log_cnt = 0;int masu_log[512345];int masu_pos[512345];struct node_s* ans[512345];struct node_s* calc(int node) {struct node_s *next_ans;if (ans[node]) return ans[node];if (masu_pos[node]) {struct node_s *first, *last, *ans_acc;int i;int offset;first = get_node();
#include <stdio.h>
struct node_s {
int value;
struct node_s *prev, *next;
};
int pnext = 0;
struct node_s pool[512345];
struct node_s* get_node(void) {
return &pool[pnext++];
}
int get_offset(int syuki) {
int ans = 1, a = 10, b = 100;
while (b > 0) {
if (b & 1) ans = (int)((long long)ans * a % syuki);
a = (int)((long long)a * a % syuki);
b >>= 1;
}
return ans;
}
int N;
int A[512345];
int masu_log_cnt = 0;
int masu_log[512345];
int masu_pos[512345];
struct node_s* ans[512345];
struct node_s* calc(int node) {
struct node_s *next_ans;
if (ans[node]) return ans[node];
if (masu_pos[node]) {
struct node_s *first, *last, *ans_acc;
int i;
int offset;
first = get_node();
first->value = node;
last = first;
for (i = masu_pos[node] + 1; i <= masu_log_cnt; i++) {
struct node_s* new_node = get_node();
new_node->value = masu_log[i];
last->next = new_node;
new_node->prev = last;
last = new_node;
}
first->prev = last;
last->next = first;
offset = get_offset(masu_log_cnt - masu_pos[node] + 1);
ans_acc = first;
for (i = 0; i < offset; i++) ans_acc = ans_acc->next;
return ans[node] = ans_acc;
}
masu_log[++masu_log_cnt] = node;
masu_pos[node] = masu_log_cnt;
next_ans = calc(A[node]);
return ans[node] = next_ans->prev;
}
int main(void) {
int i;
if (scanf("%d", &N) != 1) return 1;
for (i = 1; i <= N; i++) {
if (scanf("%d", &A[i]) != 1) return 1;
}
for (i = 1; i <= N; i++) {
if (ans[i] == NULL) {
masu_log_cnt = 0;
calc(i);
}
printf(" %d" + (i == 1), ans[i]->value);
}
putchar('\n');
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Sugoroku Destination |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 300 |
| Code Size | 1669 Byte |
| Status | AC |
| Exec Time | 69 ms |
| Memory | 52904 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1736 KiB |
| 00_sample_01.txt | AC | 0 ms | 1716 KiB |
| 00_sample_02.txt | AC | 0 ms | 1644 KiB |
| 01_random_03.txt | AC | 65 ms | 11696 KiB |
| 01_random_04.txt | AC | 66 ms | 11692 KiB |
| 01_random_05.txt | AC | 67 ms | 11692 KiB |
| 01_random_06.txt | AC | 66 ms | 11688 KiB |
| 01_random_07.txt | AC | 66 ms | 11688 KiB |
| 01_random_08.txt | AC | 65 ms | 11688 KiB |
| 01_random_09.txt | AC | 67 ms | 11688 KiB |
| 01_random_10.txt | AC | 67 ms | 11684 KiB |
| 01_random_11.txt | AC | 21 ms | 4564 KiB |
| 01_random_12.txt | AC | 18 ms | 4028 KiB |
| 01_random_13.txt | AC | 55 ms | 10404 KiB |
| 01_random_14.txt | AC | 4 ms | 2108 KiB |
| 01_random_15.txt | AC | 66 ms | 11692 KiB |
| 01_random_16.txt | AC | 1 ms | 1596 KiB |
| 01_random_17.txt | AC | 69 ms | 52904 KiB |