# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703055 | rainboy | Odd-even (IZhO11_oddeven) | C11 | 6 ms | 292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 111
#define D 10
int main() {
static char cc[N + 1];
static int aa[N * 2], bb[N * 2], tt[N * 2];
int n, h, i, j, r, k;
scanf("%s", cc), n = strlen(cc);
for (i = 0; i < n; i++)
aa[i] = cc[n - 1 - i] - '0';
for (h = N - 1; h >= 0; h--) {
for (bb[h] = 1; bb[h] < D; bb[h]++) {
memset(tt, 0, N * 2 * sizeof *tt);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
tt[i + j] += bb[i] * bb[j];
for (i = 0; i < N; i++)
tt[i] += bb[i];
for (i = 0; i < N * 2; i++)
if (tt[i] >= D)
tt[i + 1] += tt[i] / D, tt[i] %= D;
r = 0;
for (i = N * 2 - 1; i >= 0; i--) {
r = r * D + tt[i];
tt[i] = r / 2, r %= 2;
}
for (i = N * 2 - 1; i >= 0; i--)
if (tt[i] != aa[i]) {
if (tt[i] > aa[i])
goto out;
break;
}
if (i < 0)
goto out;
}
out:
bb[h]--;
}
for (i = 0; i < N; i++)
aa[i] *= 2;
for (i = 0; i < N; i++)
if (aa[i] >= D)
aa[i] -= D, aa[i + 1]++;
for (i = 0; i < N; i++)
aa[i] -= bb[i];
aa[0]--;
for (i = 0; i < N; i++)
if (aa[i] < 0) {
k = (-aa[i] + 9) / D;
aa[i] += k * D, aa[i + 1] -= k;
}
i = N - 1;
while (aa[i] == 0)
i--;
while (i >= 0)
printf("%d", aa[i--]);
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |