Submission #962630

# Submission time Handle Problem Language Result Execution time Memory
962630 2024-04-14T04:25:22 Z nguyentunglam Wombats (IOI13_wombats) C++17
76 / 100
20000 ms 253680 KB
#include<bits/stdc++.h>
using namespace std;
#include "wombats.h"

const int M = 6e7 / 200 / 200;

int T[M + 10][200][200];

int h[5010][210], v[5010][210];

int f[210][210], opt[210][210];

int r, c;

void calc (int l, int r) {
  for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) f[i][j] = (i == j ? 0 : 1e9);
  for(int row = l; row <= r; row++) {
    if (row != l) {
      for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) {
        f[i][j] += v[row - 1][j];
      }
    }
    for(int i = 0; i < c; i++) {
      for(int j = 1; j < c; j++) f[i][j] = min(f[i][j], f[i][j - 1] + h[row][j - 1]);
      for(int j = c - 2; j >= 0; j--) f[i][j] = min(f[i][j], f[i][j + 1] + h[row][j]);
    }
  }
}

void up (int s, int l, int r, int pos) {
//  if (s == 2) cout << l << " " << r << endl;
  if (s * 2 > M || l == r) {
    calc(l, r);
    for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) T[s][i][j] = f[i][j];
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) up(s << 1, l, mid, pos);
  else up(s << 1 | 1, mid + 1, r, pos);

  for(int i = c - 1; i >= 0; i--) for(int j = 0; j < c; j++) {
    T[s][i][j] = 2e9;
    int st = j - 1 >= 0 ? opt[i][j - 1] : 0;
    int ed = i + 1 < c ? opt[i + 1][j] : c - 1;
    for(int k = st; k <= ed; k++) {
      int cost = T[s << 1][i][k] + v[mid][k] + T[s << 1 | 1][k][j];
      if (T[s][i][j] > cost) {
        T[s][i][j] = cost;
        opt[i][j] = k;
      }
    }
  }
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    /* ... */
  r = R;
  c = C;
  for(int i = 0; i < r; i++) for(int j = 0; j + 1 < c; j++) h[i][j] = H[i][j];
  for(int i = 0; i + 1 < r; i++) for(int j = 0; j < c; j++) v[i][j] = V[i][j];
  for(int i = 0; i < r; i++) up(1, 0, r - 1, i);
//  cout << T[2][2][1];
//  exit(0);
//  for(int i = 0; i < r; i++) {
//    for(int j = 0; j + 1 < c; j++) cout << h[i][j] << " ";
//    cout << endl;
//  }
//
//  for(int i = 0; i + 1 < r; i++) {
//    for(int j = 0; j < c; j++) cout << v[i][j] << " ";
//    cout << endl;
//  }
}

void changeH(int P, int Q, int W) {
  h[P][Q] = W;
  up(1, 0, r - 1, P);
}

void changeV(int P, int Q, int W) {
  v[P][Q] = W;
  up(1, 0, r - 1, P);
}

int escape(int V1, int V2) {
  return T[1][V1][V2];
}

#ifdef ngu

#define fail(s, x...) do { \
		fprintf(stderr, s "\n", ## x); \
		exit(1); \
	} while(0)

static int H[5000][200];
static int V[5000][200];

int main() {
  freopen ("task.out", "w", stdout);
	int R, C, E, P, Q, W, V1, V2, event, i, j;
	int res;
	FILE *f = fopen("task.inp", "r");
	if (!f)
		fail("Failed to open input file.");

	res = fscanf(f, "%d%d", &R, &C);
    for (i = 0; i < R; ++i)
        for (j = 0; j < C-1; ++j)
            res = fscanf(f, "%d", &H[i][j]);
    for (i = 0; i < R-1; ++i)
        for (j = 0; j < C; ++j)
            res = fscanf(f, "%d", &V[i][j]);

    init(R, C, H, V);

	res = fscanf(f, "%d", &E);
	for (i = 0; i < E; i++) {
		res = fscanf(f, "%d", &event);
        if (event == 1) {
            res = fscanf(f, "%d%d%d", &P, &Q, &W);
            changeH(P, Q, W);
        } else if (event == 2) {
            res = fscanf(f, "%d%d%d", &P, &Q, &W);
            changeV(P, Q, W);
        } else if (event == 3) {
            res = fscanf(f, "%d%d", &V1, &V2);
            cout << escape(V1, V2) << endl;
//            printf("%d\n", escape(V1, V2));
        } else
            fail("Invalid event type.");
	}

	fclose(f);
	return 0;
}
#endif // ngu

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp: In function 'void up(int, int, int, int)':
wombats.cpp:37:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   int mid = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 139096 KB Output is correct
2 Correct 20 ms 139352 KB Output is correct
3 Correct 78 ms 140628 KB Output is correct
4 Correct 21 ms 139252 KB Output is correct
5 Correct 19 ms 139088 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 2 ms 16732 KB Output is correct
11 Correct 57 ms 17900 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 42324 KB Output is correct
2 Correct 72 ms 42320 KB Output is correct
3 Correct 100 ms 42272 KB Output is correct
4 Correct 91 ms 42324 KB Output is correct
5 Correct 86 ms 42352 KB Output is correct
6 Correct 1 ms 6744 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 207 ms 42224 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 143628 KB Output is correct
2 Correct 21 ms 143964 KB Output is correct
3 Correct 21 ms 143708 KB Output is correct
4 Correct 47 ms 144588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 42324 KB Output is correct
2 Correct 71 ms 42412 KB Output is correct
3 Correct 91 ms 42576 KB Output is correct
4 Correct 89 ms 42320 KB Output is correct
5 Correct 85 ms 42324 KB Output is correct
6 Correct 20 ms 143708 KB Output is correct
7 Correct 20 ms 143708 KB Output is correct
8 Correct 21 ms 143760 KB Output is correct
9 Correct 48 ms 144696 KB Output is correct
10 Correct 18 ms 139100 KB Output is correct
11 Correct 17 ms 139020 KB Output is correct
12 Correct 70 ms 140628 KB Output is correct
13 Correct 18 ms 139100 KB Output is correct
14 Correct 18 ms 139100 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 16728 KB Output is correct
19 Correct 3 ms 16728 KB Output is correct
20 Correct 2 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 3 ms 16732 KB Output is correct
25 Correct 55 ms 17828 KB Output is correct
26 Correct 2 ms 16728 KB Output is correct
27 Correct 205 ms 42460 KB Output is correct
28 Correct 5143 ms 199932 KB Output is correct
29 Correct 3838 ms 199876 KB Output is correct
30 Correct 4128 ms 199868 KB Output is correct
31 Correct 5092 ms 200916 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 42576 KB Output is correct
2 Correct 81 ms 42324 KB Output is correct
3 Correct 88 ms 42328 KB Output is correct
4 Correct 90 ms 42320 KB Output is correct
5 Correct 89 ms 42412 KB Output is correct
6 Correct 21 ms 143704 KB Output is correct
7 Correct 20 ms 143804 KB Output is correct
8 Correct 20 ms 143708 KB Output is correct
9 Correct 55 ms 144464 KB Output is correct
10 Correct 19 ms 139096 KB Output is correct
11 Correct 18 ms 139100 KB Output is correct
12 Correct 71 ms 140624 KB Output is correct
13 Correct 18 ms 139100 KB Output is correct
14 Correct 18 ms 139100 KB Output is correct
15 Correct 18949 ms 251912 KB Output is correct
16 Execution timed out 20019 ms 253680 KB Time limit exceeded
17 Halted 0 ms 0 KB -