Submission #962617

#TimeUsernameProblemLanguageResultExecution timeMemory
962617nguyentunglamWombats (IOI13_wombats)C++17
55 / 100
20094 ms26384 KiB
#include<bits/stdc++.h>
using namespace std;
#include "wombats.h"

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

int f[210][210];

int r, c;

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++) {
//    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;
    /* ... */
}

void changeV(int P, int Q, int W) {
    /* ... */
  v[P][Q] = W;
}

void update (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]);
    }
  }
}

int escape(int V1, int V2) {
  update(0, r - 1);
  return f[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() {
  ofstream cout("task.out");
	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);
            printf("%d\n", escape(V1, V2));
        } else
            fail("Invalid event type.");
	}

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

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...