답안 #60258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60258 2018-07-23T23:04:53 Z ksun48 웜뱃 (IOI13_wombats) C++14
55 / 100
9498 ms 263168 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<vector<int> > Paths;
const int MAXD = 100000000; // 1e8

int r;
int c;

vector<vector<int> > h;
vector<vector<int> > v;

void pr(const Paths &ans){
	for(int i = 0; i < c; i++){
		for(int j = 0; j < c; j++){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void dnc(const Paths &a, const Paths &b, Paths &paths, int t, int bl, int br, int ml, int mr){
	if(bl > br) return;
	// top, bottom left, bottom right
	int bm = (bl + br) / 2;
	int best = MAXD + 1;
	int bestm = -1;
	for(int m = ml; m <= mr; m++){
		int dist = a[t][m] + b[m][bm];
		if(dist < best){
			best = dist;
			bestm = m;
		}
	}
	assert(bestm != -1);
	paths[t][bm] = best;
	dnc(a, b, paths, t, bl, bm - 1, ml, bestm);
	dnc(a, b, paths, t, bm + 1, br, bestm, mr);
}

Paths join(const Paths &a, const Paths &b){
	Paths paths(c, vector<int>(c, MAXD));
	for(int i = 0; i < c; i++){
		dnc(a, b, paths, i, 0, c-1, 0, c-1);
	}
	return paths;
}

Paths horizontal(int row){
	vector<int> psums(c);
	psums[0] = 0;
	for(int i = 1; i < c; i++){
		psums[i] = psums[i-1] + h[row][i-1];
	}
	Paths paths(c, vector<int>(c, MAXD));
	for(int i = 0; i < c; i++){
		for(int j = 0; j < c; j++){
			paths[i][j] = abs(psums[j] - psums[i]);
		}
	}
	return paths;
}

Paths empty(){
	Paths p2(c, vector<int>(c, MAXD));
	for(int i = 0; i < c; i++){
		p2[i][i] = 0;
	}
	return p2;
}

Paths make(int row){
	Paths p2(c, vector<int>(c, MAXD));
	for(int i = 0; i < c; i++){
		p2[i][i] = v[row][i];
	}
	return join(horizontal(row), join(p2, horizontal(row + 1)));
}

Paths make_interval(int r1, int r2){
	Paths p = empty();
	for(int a = r1; a <= r2; a++){
		p = join(p, make(a));
	}
	return p;
}

Paths ans;

struct node {
	Paths p;
	node *l, *r;
	int lx, rx;
};

const int BLOCKSZ = 1;

node* build(int lx, int rx){
	node* a = new node();
	a->lx = lx;
	a->rx = rx;
	if(rx - lx + 1 <= BLOCKSZ){
		a->l = a->r = NULL;
		a->p = make_interval(lx, rx);
	} else {
		int mx = (lx + rx) / 2;
		a->l = build(lx, mx);
		a->r = build(mx + 1, rx);
		a->p = join(a->l->p, a->r->p);
	}
	return a;
}

void upd(node* v, int x){
	if(x < v->lx || x > v->rx) return;
	if(v->l == NULL && v->r == NULL){
		v->p = make(x);
	} else {
		upd(v->l, x);
		upd(v->r, x);
		v->p = join(v->l->p, v->r->p);
	}
}

node* tree;

void init(int R, int C, int H[5000][200], int V[5000][200]) {
	r = R;
	c = C;
	h.resize(r, vector<int>(c-1, 0));
	v.resize(r-1, vector<int>(c, 0));
	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];
		}
	}
	tree = build(0, r-2);
}

void changeH(int P, int Q, int W) {
	h[P][Q] = W;
	upd(tree, P-1);
	upd(tree, P);
}

void changeV(int P, int Q, int W) {
	v[P][Q] = W;
	upd(tree, P);
}

int escape(int V1, int V2) {
	return tree->p[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 Correct 15 ms 5880 KB Output is correct
2 Correct 15 ms 5880 KB Output is correct
3 Correct 90 ms 7596 KB Output is correct
4 Correct 16 ms 7596 KB Output is correct
5 Correct 15 ms 7596 KB Output is correct
6 Correct 2 ms 7596 KB Output is correct
7 Correct 2 ms 7596 KB Output is correct
8 Correct 2 ms 7596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7596 KB Output is correct
2 Correct 2 ms 7596 KB Output is correct
3 Correct 2 ms 7596 KB Output is correct
4 Correct 3 ms 7596 KB Output is correct
5 Correct 3 ms 7596 KB Output is correct
6 Correct 3 ms 7596 KB Output is correct
7 Correct 4 ms 7596 KB Output is correct
8 Correct 4 ms 7596 KB Output is correct
9 Correct 3 ms 7596 KB Output is correct
10 Correct 3 ms 7596 KB Output is correct
11 Correct 90 ms 7596 KB Output is correct
12 Correct 3 ms 7596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 9412 KB Output is correct
2 Correct 298 ms 9436 KB Output is correct
3 Correct 675 ms 9724 KB Output is correct
4 Correct 347 ms 9724 KB Output is correct
5 Correct 475 ms 9724 KB Output is correct
6 Correct 2 ms 9724 KB Output is correct
7 Correct 2 ms 9724 KB Output is correct
8 Correct 3 ms 9724 KB Output is correct
9 Correct 1980 ms 9724 KB Output is correct
10 Correct 2 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 10876 KB Output is correct
2 Correct 23 ms 10880 KB Output is correct
3 Correct 25 ms 10892 KB Output is correct
4 Correct 64 ms 11676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 463 ms 11676 KB Output is correct
2 Correct 292 ms 11676 KB Output is correct
3 Correct 765 ms 11676 KB Output is correct
4 Correct 357 ms 11676 KB Output is correct
5 Correct 478 ms 11676 KB Output is correct
6 Correct 25 ms 11676 KB Output is correct
7 Correct 36 ms 11676 KB Output is correct
8 Correct 24 ms 11676 KB Output is correct
9 Correct 66 ms 11736 KB Output is correct
10 Correct 15 ms 11736 KB Output is correct
11 Correct 16 ms 11736 KB Output is correct
12 Correct 99 ms 11736 KB Output is correct
13 Correct 24 ms 11736 KB Output is correct
14 Correct 14 ms 11736 KB Output is correct
15 Correct 2 ms 11736 KB Output is correct
16 Correct 2 ms 11736 KB Output is correct
17 Correct 2 ms 11736 KB Output is correct
18 Correct 3 ms 11736 KB Output is correct
19 Correct 3 ms 11736 KB Output is correct
20 Correct 3 ms 11736 KB Output is correct
21 Correct 4 ms 11736 KB Output is correct
22 Correct 3 ms 11736 KB Output is correct
23 Correct 4 ms 11736 KB Output is correct
24 Correct 3 ms 11736 KB Output is correct
25 Correct 131 ms 11736 KB Output is correct
26 Correct 4 ms 11736 KB Output is correct
27 Correct 2300 ms 11736 KB Output is correct
28 Runtime error 9498 ms 263168 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.
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 529 ms 263168 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 -