Submission #74707710
Source Code Expand
Copy
#include <stdio.h>struct node_s {int A;struct node_s *prev, *next;};struct node_s nodes[212345];int main(void) {int N, i;struct node_s *cur;int ans;if (scanf("%d", &N) != 1) return 1;for (i = 1; i <= N; i++) {if (scanf("%d", &nodes[i].A) != 1) return 1;nodes[i].prev = &nodes[i - 1];nodes[i].next = &nodes[i + 1];}nodes[N].next = NULL;nodes[0].next = &nodes[1];ans = N;cur = &nodes[1];for (;;) {/* 4つ揃ったか判定 */int combo = 0;struct node_s *cur2;for (cur2 = cur, i = 0; cur2 != NULL && i < 4; cur2 = cur2->next, i++) {if (cur->A == cur2->A) combo++;}if (i < 4) break; /* 4つ揃わず、終端を迎えた */if (combo == 4) {/* 揃った → 消して3個戻す */if (cur2 != NULL) cur2->prev = cur->prev;cur->prev->next = cur2;ans -= 4;for (i = 0; i < 3 && cur->prev != NULL; i++) {cur = cur->prev;}} else {/* 揃ってない → 次へ */
#include <stdio.h>
struct node_s {
int A;
struct node_s *prev, *next;
};
struct node_s nodes[212345];
int main(void) {
int N, i;
struct node_s *cur;
int ans;
if (scanf("%d", &N) != 1) return 1;
for (i = 1; i <= N; i++) {
if (scanf("%d", &nodes[i].A) != 1) return 1;
nodes[i].prev = &nodes[i - 1];
nodes[i].next = &nodes[i + 1];
}
nodes[N].next = NULL;
nodes[0].next = &nodes[1];
ans = N;
cur = &nodes[1];
for (;;) {
/* 4つ揃ったか判定 */
int combo = 0;
struct node_s *cur2;
for (cur2 = cur, i = 0; cur2 != NULL && i < 4; cur2 = cur2->next, i++) {
if (cur->A == cur2->A) combo++;
}
if (i < 4) break; /* 4つ揃わず、終端を迎えた */
if (combo == 4) {
/* 揃った → 消して3個戻す */
if (cur2 != NULL) cur2->prev = cur->prev;
cur->prev->next = cur2;
ans -= 4;
for (i = 0; i < 3 && cur->prev != NULL; i++) {
cur = cur->prev;
}
} else {
/* 揃ってない → 次へ */
cur = cur->next;
}
}
printf("%d\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - 1D puyopuyo |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 300 |
| Code Size | 1064 Byte |
| Status | AC |
| Exec Time | 13 ms |
| Memory | 6444 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_00.txt, 01_random_01.txt, 01_random_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 | 1688 KiB |
| 00_sample_01.txt | AC | 0 ms | 1616 KiB |
| 00_sample_02.txt | AC | 0 ms | 1716 KiB |
| 01_random_00.txt | AC | 0 ms | 1696 KiB |
| 01_random_01.txt | AC | 12 ms | 6444 KiB |
| 01_random_02.txt | AC | 12 ms | 6416 KiB |
| 01_random_03.txt | AC | 12 ms | 6424 KiB |
| 01_random_04.txt | AC | 13 ms | 6432 KiB |
| 01_random_05.txt | AC | 12 ms | 6308 KiB |
| 01_random_06.txt | AC | 13 ms | 6308 KiB |
| 01_random_07.txt | AC | 13 ms | 6432 KiB |
| 01_random_08.txt | AC | 13 ms | 6424 KiB |
| 01_random_09.txt | AC | 12 ms | 6384 KiB |
| 01_random_10.txt | AC | 12 ms | 6444 KiB |
| 01_random_11.txt | AC | 12 ms | 6384 KiB |
| 01_random_12.txt | AC | 11 ms | 6432 KiB |
| 01_random_13.txt | AC | 11 ms | 6392 KiB |
| 01_random_14.txt | AC | 11 ms | 6352 KiB |
| 01_random_15.txt | AC | 11 ms | 6432 KiB |
| 01_random_16.txt | AC | 12 ms | 6424 KiB |
| 01_random_17.txt | AC | 11 ms | 6416 KiB |