Submission #65081

# Submission time Handle Problem Language Result Execution time Memory
65081 2018-08-06T14:54:18 Z gnoor Wombats (IOI13_wombats) C++17
16 / 100
1505 ms 46284 KB
#include "wombats.h"

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

using namespace std;

typedef vector<vector<int>> tbl;

int r,c;

int opt[200][200];
void combine(tbl &tmp,const tbl &a, const tbl &b) {
	for (auto &i:tmp) for (auto &j:i) j=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;
				}
			}
		}
	}
}

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

int qsh[5000][200];

//0 <= row < r-1
void build(tbl &tmp, int row) {
	for (auto &i:tmp) for (auto &j:i) j=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;
				}
			}
		}
	}
}

tbl seg[20100];

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

void update(int id,int ll,int rr,int k) {
	if (ll+1==rr) {
		build(seg[id],ll);
		return;
	}
	int m=(ll+rr)>>1;
	if (k<m) update(id*2,ll,m,k);
	else update(id*2+1,m,rr,k);
	combine(seg[id],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];
		}
	}
	for (int i=1;i<3*R;i++) {
		seg[i].resize(c,vector<int>(c));
	}
	buildseg(1,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(1,0,r-1,P);
	if (P) update(1,0,r-1,P-1);
}

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

int escape(int V1, int V2) {
	return seg[1][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;
      ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 34556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 34556 KB Output is correct
2 Correct 3 ms 34556 KB Output is correct
3 Correct 4 ms 34556 KB Output is correct
4 Runtime error 10 ms 34556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 342 ms 34556 KB Output is correct
2 Correct 229 ms 34556 KB Output is correct
3 Correct 359 ms 34556 KB Output is correct
4 Correct 219 ms 34556 KB Output is correct
5 Correct 369 ms 34556 KB Output is correct
6 Correct 4 ms 34556 KB Output is correct
7 Correct 3 ms 34556 KB Output is correct
8 Correct 3 ms 34556 KB Output is correct
9 Correct 1505 ms 34556 KB Output is correct
10 Correct 5 ms 34556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 45216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 368 ms 45216 KB Output is correct
2 Correct 181 ms 45216 KB Output is correct
3 Correct 467 ms 45216 KB Output is correct
4 Correct 258 ms 45216 KB Output is correct
5 Correct 299 ms 45216 KB Output is correct
6 Runtime error 56 ms 45724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 360 ms 45724 KB Output is correct
2 Correct 240 ms 45724 KB Output is correct
3 Correct 412 ms 45724 KB Output is correct
4 Correct 230 ms 45724 KB Output is correct
5 Correct 302 ms 45724 KB Output is correct
6 Runtime error 65 ms 46284 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -