# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
830838 | rainboy | Liteh and Newfiteh (INOI20_litehfiteh) | C11 | 81 ms | 14644 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 100000
#define L 16 /* L = floor(log2(N)) */
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int main() {
static int aa[N], dp[N][L + 1], dq[N][L + 1], dr[N + 1];
int n, i, j, l, a;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++)
if (aa[i] > L + 1) {
printf("-1\n");
return 0;
}
for (l = 0; 1 << l <= n; l++) {
if (l == 0)
for (i = 0; i < n; i++)
memset(dp[i], 0x3f, (L + 1) * sizeof *dp[i]), dp[i][aa[i]] = 0;
else
for (i = 0; i + (1 << l) <= n; i++)
for (a = 0; a <= L; a++)
dp[i][a] = min(dp[i][a] + dp[i + (1 << l - 1)][a], INF);
for (i = 0; i < n; i++)
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |