답안 #65021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65021 2018-08-06T12:57:48 Z gnoor 웜뱃 (IOI13_wombats) C++17
12 / 100
265 ms 23104 KB
#include "wombats.h"

#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

typedef vector<vector<int>> tbl;

int r,c;

int opt[200][200];
tbl combine(const tbl &a, const tbl &b) {
	tbl tmp(c,vector<int>(c,1e9));
	for (int sz=-c+1;sz<c;sz++) {
		for (int i=0;i<c;i++) {
			int j=i+sz;
			if (j<0||j>=c) continue;
			for (int k=(j==0?0:opt[i][j-1]);k<=(i==c-1?c-1:opt[i+1][j]);k++) {
				if (a[i][k]+b[k][j]<tmp[i][j]) {
					tmp[i][j]=a[i][k]+b[k][j];
					opt[i][j]=k;
				}
			}
		}
	}
	return tmp;
}

int h[5000][200];
int v[5000][200];

int qsh[5000][200];

//0 <= row < r-1
tbl build(int row) {
	tbl tmp(c,vector<int>(c,1e9));
	int da,db;
	for (int sz=-c+1;sz<c;sz++) {
		for (int i=0;i<c;i++) {
			int j=i+sz;
			if (j<0||j>=c) continue;
			for (int k=(j==0?0:opt[i][j-1]);k<=(i==c-1?c-1:opt[i+1][j]);k++) {
				da=abs((k==0?0:qsh[row][k-1])-(i==0?0:qsh[row][i-1]));
				db=abs((k==0?0:qsh[row+1][k-1])-(j==0?0:qsh[row+1][j-1]));
				if (da+db+v[row][k]<tmp[i][j]) {
					tmp[i][j]=da+db+v[row][k];
					opt[i][j]=k;
				}
			}
		}
	}
	return tmp;
}

tbl seg[30100];

void buildseg(int id,int ll,int rr) {
	if (ll+1==rr) {
		seg[id]=build(ll);
		return;
	}
	int m=(ll+rr)>>1;
	buildseg(id*2,ll,m);
	buildseg(id*2+1,m,rr);
	seg[id]=combine(seg[id*2],seg[id*2+1]);
}

void update(int id,int ll,int rr,int k) {
	if (ll+1==rr) {
		seg[id]=build(ll);
		return;
	}
	int m=(ll+rr)>>1;
	if (k<m) update(id*2,ll,m,k);
	else update(id*2+1,m,rr,k);
	seg[id]=combine(seg[id*2],seg[id*2+1]);
}

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;j++) {
			h[i][j]=H[i][j];
			v[i][j]=V[i][j];
		}
	}
	for (int i=0;i<r;i++) {
		qsh[i][0]=h[i][0];
		for (int j=1;j<c-1;j++) {
			qsh[i][j]=qsh[i][j-1]+h[i][j];
		}
	}
	buildseg(0,0,r-1);
}

void changeH(int P, int Q, int W) {
	h[P][Q]=W;
	qsh[P][0]=h[P][0];
	for (int j=1;j<c-1;j++) {
		qsh[P][j]=qsh[P][j-1]+h[P][j];
	}
	update(0,0,r-1,P);
}

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

int escape(int V1, int V2) {
	return seg[0][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 24 ms 17016 KB Output is correct
2 Incorrect 24 ms 17032 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 17032 KB Output is correct
2 Correct 3 ms 17032 KB Output is correct
3 Correct 4 ms 17032 KB Output is correct
4 Correct 4 ms 17032 KB Output is correct
5 Correct 5 ms 17032 KB Output is correct
6 Correct 4 ms 17032 KB Output is correct
7 Correct 4 ms 17032 KB Output is correct
8 Correct 4 ms 17032 KB Output is correct
9 Correct 4 ms 17032 KB Output is correct
10 Correct 5 ms 17032 KB Output is correct
11 Correct 114 ms 17032 KB Output is correct
12 Correct 4 ms 17032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 265 ms 17032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 23104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 223 ms 23104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 23104 KB Output isn't correct
2 Halted 0 ms 0 KB -