답안 #480313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480313 2021-10-15T15:30:04 Z AdamGS 웜뱃 (IOI13_wombats) C++14
27 / 100
1878 ms 89180 KB
#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int MAXN=5e3+7, MAXM=207, N=1<<9, INF=1e9+7;
int tr[2*N][200][200];
int A[10*N+1][MAXM], B[10*N+1][MAXM], n, m;
void liczlisc(int x) {
	int dwa[10][m][m];
	rep(i, 10) {
		int pref[m][2];
		pref[0][0]=pref[0][1]=2;
		rep(j, m-1) {
			pref[j+1][0]=pref[j][0]+A[10*x+i][j];
			pref[j+1][1]=pref[j][1]+A[10*x+i+1][j];
		}
		int lst[m+1], lst2[m+1];
		lst[0]=lst2[0]=0;
		lst[1]=lst2[1]=m-1;
		for(int r=m-1; r>=0; --r) {
			int akt[m+1], akt2[m+1];
			akt[0]=akt2[0]=0;
			akt[m-r+1]=akt2[m-r+1]=m-1;
			rep(p, m-r) {
				int k=p+r;
				pair<int,int>mi={INF, INF};
				for(int l=lst[p]; l<=lst[p+1]; ++l) {
					mi=min(mi, {abs(pref[l][0]-pref[p][0])+abs(pref[k][1]-pref[l][1])+B[10*x+i][l], l});
				}
				akt[p+1]=mi.nd;
				dwa[i][p][k]=mi.st;
				mi={INF, INF};
				for(int l=lst2[p]; l<=lst2[p+1]; ++l) {
					mi=min(mi, {abs(pref[k][0]-pref[l][0])+abs(pref[l][1]-pref[p][1])+B[10*x+i][l], l});
				}
				akt2[p+1]=mi.nd;
				dwa[i][k][p]=mi.st;
			}
			rep(p, m-r+2) {
				lst[p]=akt[p];
				lst2[p]=akt2[p];
			}
		}
	}
	rep(i, m) rep(j, m) tr[N+x][i][j]=dwa[0][i][j];
	rep(i, 9) {
		int tmp[m][m], lst[m+1], lst2[m+1];
		lst[0]=lst2[0]=0;
		lst[1]=lst2[1]=m-1;
		for(int r=m-1; r>=0; --r) {
			int akt[m+1], akt2[m+1];
			akt[0]=akt2[0]=0;
			akt[m-r+1]=akt2[m-r+1]=m-1;
			rep(p, m-r) {
				int k=p+r;
				pair<int,int>mi={INF, INF};
				for(int l=lst[p]; l<=lst[p+1]; ++l) {
					mi=min(mi, {tr[N+x][p][l]+dwa[i+1][l][k], l});
				}
				akt[p+1]=mi.nd;
				tmp[p][k]=mi.st;
				mi={INF, INF};
				for(int l=lst2[p]; l<=lst2[p+1]; ++l) {
					mi=min(mi, {tr[N+x][k][l]+dwa[i+1][l][p], l});
				}
				akt2[p+1]=mi.nd;
				tmp[k][p]=mi.st;
			}
			rep(p, m-r+2) {
				lst[p]=akt[p];
				lst2[p]=akt2[p];
			}
		}
		rep(j, m) rep(l, m) tr[N+x][j][l]=tmp[j][l];
	}
}
void liczwierzcholek(int v) {
	int lst[m+1], lst2[m+1];
	lst[0]=lst2[0]=0;
	lst[1]=lst2[1]=m-1;
	for(int r=m-1; r>=0; --r) {
		int akt[m+1], akt2[m+1];
		akt[0]=akt2[0]=0;
		akt[m-r+1]=akt2[m-r+1]=m-1;
		rep(p, m-r) {
			int k=p+r;
			pair<int,int>mi={INF, INF};
			for(int l=lst[p]; l<=lst[p+1]; ++l) {
				mi=min(mi, {tr[2*v][p][l]+tr[2*v+1][l][k], l});
			}
			akt[p+1]=mi.nd;
			tr[v][p][k]=mi.st;
			mi={INF, INF};
			for(int l=lst2[p]; l<=lst2[p+1]; ++l) {
				mi=min(mi, {tr[2*v][k][l]+tr[2*v+1][l][p], l});
			}
			akt2[p+1]=mi.nd;
			tr[v][k][p]=mi.st;
		}
		rep(p, m-r+2) {
			lst[p]=akt[p];
			lst2[p]=akt2[p];
		}
	}
}
void upd(int v) {
	liczlisc(v);
	v+=N;
	while(v>1) {
		v/=2;
		liczwierzcholek(v);
	}
}
void changeH(int a, int b, int c) {
	A[a][b]=c;
	upd(a/10);
	if(a%10==0 && a) upd(a/10-1);
}
void changeV(int a, int b, int c) {
	B[a][b]=c;
	upd(a/10);
}
int escape(int v1, int v2) {
	return tr[1][v1][v2];
}
void init(int r, int c, int H[5000][200], int V[5000][200]) {
	n=r; m=c;
	rep(i, n) rep(j, m-1) A[i][j]=H[i][j];
	rep(i, n-1) rep(j, m) B[i][j]=V[i][j];
	for(int i=n; i<=10*N; ++i) rep(j, m-1) A[i][j]=5001007;
	rep(i, N) liczlisc(i);
	for(int i=N-1; i; --i) liczwierzcholek(i);
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12680 KB Output is correct
2 Correct 9 ms 12620 KB Output is correct
3 Correct 104 ms 14224 KB Output is correct
4 Correct 7 ms 12620 KB Output is correct
5 Correct 11 ms 12620 KB Output is correct
6 Correct 4 ms 4684 KB Output is correct
7 Correct 4 ms 4684 KB Output is correct
8 Correct 5 ms 4684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4684 KB Output is correct
2 Correct 3 ms 4684 KB Output is correct
3 Correct 3 ms 4684 KB Output is correct
4 Correct 69 ms 24188 KB Output is correct
5 Correct 70 ms 24152 KB Output is correct
6 Correct 71 ms 24256 KB Output is correct
7 Correct 71 ms 24232 KB Output is correct
8 Incorrect 69 ms 23140 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1768 ms 89028 KB Output is correct
2 Correct 1633 ms 88300 KB Output is correct
3 Correct 1787 ms 88992 KB Output is correct
4 Correct 1761 ms 89064 KB Output is correct
5 Incorrect 1737 ms 88264 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 21396 KB Output is correct
2 Correct 14 ms 21452 KB Output is correct
3 Correct 14 ms 21452 KB Output is correct
4 Correct 52 ms 22160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1762 ms 89048 KB Output is correct
2 Correct 1638 ms 88164 KB Output is correct
3 Correct 1878 ms 89060 KB Output is correct
4 Correct 1805 ms 89180 KB Output is correct
5 Incorrect 1794 ms 88336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1767 ms 88980 KB Output is correct
2 Correct 1637 ms 88268 KB Output is correct
3 Correct 1833 ms 89096 KB Output is correct
4 Correct 1749 ms 88944 KB Output is correct
5 Incorrect 1755 ms 88192 KB Output isn't correct
6 Halted 0 ms 0 KB -