답안 #480310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480310 2021-10-15T15:27:44 Z AdamGS 웜뱃 (IOI13_wombats) C++14
컴파일 오류
0 ms 0 KB
#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);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int r, c, H[5000][200], V[5000][200];
	cin >> r >> c;
	rep(i, r) rep(j, c-1) cin >> H[i][j];
	rep(i, r-1) rep(j, c) cin >> V[i][j];
	init(r, c, H, V);
	int e;
	cin >> e;
	while(e--) {
		int t;
		cin >> t;
		if(t==1) {
			int x, y, z;
			cin >> x >> y >> z;
			changeH(x, y, z);
		} else if(t==2) {
			int x, y, z;
			cin >> x >> y >> z;
			changeV(x, y, z);
		} else {
			int x, y;
			cin >> x >> y;
			cout << escape(x, y) << '\n';
		}
	}
}

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;
      |      ^~~
/usr/bin/ld: /tmp/ccu9qayP.o: in function `main':
wombats.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccS81pVS.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccS81pVS.o: in function `main':
grader.c:(.text.startup+0x129): undefined reference to `init'
/usr/bin/ld: grader.c:(.text.startup+0x194): undefined reference to `escape'
/usr/bin/ld: grader.c:(.text.startup+0x203): undefined reference to `changeH'
/usr/bin/ld: grader.c:(.text.startup+0x26d): undefined reference to `changeV'
collect2: error: ld returned 1 exit status