답안 #60010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60010 2018-07-23T12:11:58 Z aome 웜뱃 (IOI13_wombats) C++11
0 / 100
20000 ms 263172 KB
#include "wombats.h"

#include <bits/stdc++.h>

using namespace std;

const int INF = 0x3f3f3f3f;

int R, C;
int sum[200];
int H[5000][200];
int V[5000][200];
int opt[200][200];

struct Node {
	int d[200][200];

	Node() {
		memset(d, INF, sizeof d);
	}
};

Node a[200];

bool upd(int &x, int y) {
	if (x > y) { x = y; return 1; }
	return 0;
}

Node merge(Node& y, Node& z, int cost[200]) {
	Node x;
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j < C; ++j) {
			if (upd(x.d[i][0], y.d[i][j] + z.d[j][0] + cost[j])) opt[i][0] = j;
		}
	}
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j < C; ++j) {
			if (upd(x.d[C - 1][i], y.d[C - 1][j] + z.d[j][i] + cost[j])) opt[C - 1][i] = j;
		}
	}
	for (int i = C - 2; i >= 0; --i) {
		for (int j = 1; j < C; ++j) {
			int l = opt[i][j - 1], r = opt[i + 1][j];
			for (int k = l; k <= r; ++k) {
				if (upd(x.d[i][j], y.d[i][k] + z.d[k][j] + cost[k])) opt[i][j] = k;
			}
		}
	}
	return x;
}

Node cal(int p) {
	Node x;
	sum[0] = 0;
	for (int i = 1; i < C; ++i) {
		sum[i] = sum[i - 1] + H[p][i - 1];
	}
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j <= i; ++j) {
			x.d[i][j] = x.d[j][i] = sum[i] - sum[j];
		}
	}
	return x;
}

struct SegmentTree {
	Node T[2000];

	#define mid ((l + r) >> 1)

	void build(int i, int l, int r) {
		if (r - l <= 10) {
			T[i] = a[l] = cal(l);
			for (int j = l; j < r; ++j) {
				T[i] = merge(T[i], a[j + 1] = cal(j + 1), V[j]);
			}
			return;
		}
		build(i << 1, l, mid);
		build(i << 1 | 1, mid + 1, r);
		T[i] = merge(T[i << 1], T[i << 1 | 1], V[mid]);
	}

	void upd(int i, int l, int r, int p) {
		if (r - l <= 10) {
			T[i] = a[l];
			for (int j = l; j < r; ++j) {
				T[i] = merge(T[i], a[j + 1], V[j]);
			}
			return;
		}
		if (mid >= p) upd(i << 1, l, mid, p);
		else upd(i << 1 | 1, mid + 1, r, p);
		T[i] = merge(T[i << 1], T[i << 1 | 1], V[mid]);
	}

	#undef mid
} IT;

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 < (C - 1); ++j) {
			H[i][j] = _H[i][j];
		}
	}
	for (int i = 0; i < (R - 1); ++i) {
		for (int j = 0; j < C; ++j) {
			V[i][j] = _V[i][j];
		}
	}
	IT.build(1, 0, R - 1);
}

void changeH(int P, int Q, int W) {
    H[P][Q] = W, a[P] = cal(P), IT.upd(1, 0, R - 1, P);
}

void changeV(int P, int Q, int W) {
    V[P][Q] = W, IT.upd(1, 0, R - 1, P);
}

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

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 19699 ms 263172 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 531 ms 263172 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 645 ms 263172 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 20145 ms 263172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 745 ms 263172 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 772 ms 263172 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -