Last active
September 13, 2025 11:03
-
-
Save oguz-ismail/2d481be2375d23342a1c2229cff07b2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define N 0x2000 | |
typedef struct { | |
long long k, v; | |
} tbl[N]; | |
static long long * | |
cell(tbl t, long long k) { | |
unsigned i; | |
for (i = k; i %= N, t[i].v && t[i].k != k; i++); | |
t[i].k = k; | |
return &t[i].v; | |
} | |
static long long | |
sum(const tbl t) { | |
long long x; | |
int i; | |
x = 0; | |
for (i = 0; i < N; i++) | |
x += t[i].v; | |
return x; | |
} | |
static void | |
blink(const tbl a, tbl b) { | |
int i; | |
long long d; | |
memset(b, 0, sizeof (tbl)); | |
for (i = 0; i < N; i++) | |
if (a[i].k == 0) { | |
*cell(b, 1) += a[i].v; | |
} | |
else { | |
for (d = 10; d <= a[i].k/d; d *= 10); | |
if (a[i].k/d >= d/10) { | |
*cell(b, a[i].k/d) += a[i].v; | |
*cell(b, a[i].k%d) += a[i].v; | |
} | |
else { | |
*cell(b, a[i].k*2024) += a[i].v; | |
} | |
} | |
} | |
int | |
main(void) { | |
tbl a[2]; | |
int x, i; | |
memset(a, 0, sizeof a); | |
do { | |
scanf("%d", &x); | |
*cell(a[0], x) = 1; | |
} | |
while (getchar() != '\n'); | |
for (i = 0; i < 75; i++) { | |
if (i == 25) | |
printf("%lld\n", sum(a[1])); | |
blink(a[i%2 != 0], a[i%2 == 0]); | |
} | |
printf("%lld\n", sum(a[1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment