답안 #198769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198769 2020-01-27T14:53:12 Z arnold518 웜뱃 (IOI13_wombats) C++14
100 / 100
9960 ms 196996 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXR = 5000;
const int MAXC = 200;
const int INF = 987654321;

int R, C, H[MAXR+10][MAXC+10], V[MAXR+10][MAXC+10];

struct Node
{
	vector<vector<int>> V;
	Node() { V=vector<vector<int>>(C, vector<int>(C)); }
};
Node tree[MAXR*4+10];
int opt[MAXC+10][MAXC+10];

void add(Node &now, Node &lc, Node &rc, int pos)
{
	int i, j, k, p;
	now=Node();

	for(k=-(C-1); k<=(C-1); k++)
	{
		for(i=max(0, k); i<min(C+k, C); i++)
		{
			j=i-k; int l, r;

			if(i==0) l=0;
			else l=opt[i-1][j];

			if(j==C-1) r=C-1;
			else r=opt[i][j+1];

			int t=l; now.V[i][j]=INF;
			for(p=l; p<=r; p++)
			{
				if(now.V[i][j]>lc.V[i][p]+rc.V[p][j]+V[pos][p])
				{
					t=p; now.V[i][j]=lc.V[i][p]+rc.V[p][j]+V[pos][p];
				}
			}
			opt[i][j]=t;
		}
	}
}

void initnode(Node &now, int tl, int tr)
{
	int i, j, k;

	now=Node();
	for(i=0; i<C; i++)
	{
		int s=0;
		for(j=i+1; j<C; j++)
		{
			s+=H[tl][j-1];
			now.V[i][j]=now.V[j][i]=s;
		}
	}

	for(k=tl+1; k<=tr; k++)
	{
		Node p;
		for(i=0; i<C; i++)
		{
			int s=0;
			for(j=i+1; j<C; j++)
			{
				s+=H[k][j-1];
				p.V[i][j]=p.V[j][i]=s;
			}
		}
		Node t;
		add(t, now, p, k-1);
		now=t;
	}
}

void init(int node, int tl, int tr)
{
	if(tr-tl+1<=10)
	{
		initnode(tree[node], tl, tr);
		return;
	}
	int mid=tl+tr>>1;
	init(node*2, tl, mid);
	init(node*2+1, mid+1, tr);
	add(tree[node], tree[node*2], tree[node*2+1], mid);
}

void init(int _R, int _C, int _H[5000][200], int _V[5000][200])
{
	int i, j;
	R=_R; C=_C;
	for(i=0; i<R; i++) for(j=0; j+1<C; j++) H[i][j]=_H[i][j];
	for(i=0; i+1<R; i++) for(j=0; j<C; j++) V[i][j]=_V[i][j];

	init(1, 0, R-1);
}

void updateH(int node, int tl, int tr, int y)
{
	if(tr-tl+1<=10)
	{
		initnode(tree[node], tl, tr);
		return;
	}
	int mid=tl+tr>>1;
	if(y<=mid) updateH(node*2, tl, mid, y);
	else updateH(node*2+1, mid+1, tr, y);
	add(tree[node], tree[node*2], tree[node*2+1], mid);
}

void updateV(int node, int tl, int tr, int y)
{
	if(tr-tl+1<=10)
	{
		initnode(tree[node], tl, tr);
		return;
	}
	int mid=tl+tr>>1;
	if(y==mid) { add(tree[node], tree[node*2], tree[node*2+1], mid); return; }
	if(y<=mid) updateV(node*2, tl, mid, y);
	else updateV(node*2+1, mid+1, tr, y);
	add(tree[node], tree[node*2], tree[node*2+1], mid);
}

void changeH(int P, int Q, int W)
{
	H[P][Q]=W;
	updateH(1, 0, R-1, P);
}

void changeV(int P, int Q, int W)
{
	V[P][Q]=W;
	updateV(1, 0, R-1, P);
}

int escape(int V1, int V2)
{
	return tree[1].V[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;
      ^~~
wombats.cpp: In function 'void init(int, int, int)':
wombats.cpp:93:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
wombats.cpp: In function 'void updateH(int, int, int, int)':
wombats.cpp:116:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
wombats.cpp: In function 'void updateV(int, int, int, int)':
wombats.cpp:129:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8824 KB Output is correct
2 Correct 14 ms 8696 KB Output is correct
3 Correct 99 ms 10488 KB Output is correct
4 Correct 14 ms 8956 KB Output is correct
5 Correct 14 ms 8824 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 6 ms 888 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 6 ms 888 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 7 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 96 ms 1876 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 2748 KB Output is correct
2 Correct 132 ms 2680 KB Output is correct
3 Correct 188 ms 2620 KB Output is correct
4 Correct 163 ms 2744 KB Output is correct
5 Correct 166 ms 2680 KB Output is correct
6 Correct 6 ms 756 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 620 ms 2744 KB Output is correct
10 Correct 6 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 17016 KB Output is correct
2 Correct 22 ms 17020 KB Output is correct
3 Correct 24 ms 17016 KB Output is correct
4 Correct 67 ms 17784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 2620 KB Output is correct
2 Correct 132 ms 2808 KB Output is correct
3 Correct 174 ms 2744 KB Output is correct
4 Correct 162 ms 2744 KB Output is correct
5 Correct 175 ms 2808 KB Output is correct
6 Correct 23 ms 17016 KB Output is correct
7 Correct 23 ms 17016 KB Output is correct
8 Correct 24 ms 17020 KB Output is correct
9 Correct 72 ms 17784 KB Output is correct
10 Correct 15 ms 8824 KB Output is correct
11 Correct 15 ms 8824 KB Output is correct
12 Correct 102 ms 10488 KB Output is correct
13 Correct 15 ms 9080 KB Output is correct
14 Correct 15 ms 8824 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 6 ms 760 KB Output is correct
18 Correct 6 ms 888 KB Output is correct
19 Correct 6 ms 888 KB Output is correct
20 Correct 6 ms 888 KB Output is correct
21 Correct 6 ms 888 KB Output is correct
22 Correct 6 ms 936 KB Output is correct
23 Correct 6 ms 888 KB Output is correct
24 Correct 6 ms 888 KB Output is correct
25 Correct 109 ms 1912 KB Output is correct
26 Correct 6 ms 888 KB Output is correct
27 Correct 637 ms 2616 KB Output is correct
28 Correct 2039 ms 65752 KB Output is correct
29 Correct 2069 ms 62504 KB Output is correct
30 Correct 2016 ms 62532 KB Output is correct
31 Correct 2155 ms 66912 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 2880 KB Output is correct
2 Correct 140 ms 2680 KB Output is correct
3 Correct 183 ms 2744 KB Output is correct
4 Correct 169 ms 2744 KB Output is correct
5 Correct 167 ms 2684 KB Output is correct
6 Correct 22 ms 17016 KB Output is correct
7 Correct 21 ms 17016 KB Output is correct
8 Correct 22 ms 17016 KB Output is correct
9 Correct 68 ms 17784 KB Output is correct
10 Correct 14 ms 8952 KB Output is correct
11 Correct 14 ms 8952 KB Output is correct
12 Correct 102 ms 10488 KB Output is correct
13 Correct 16 ms 8824 KB Output is correct
14 Correct 14 ms 8824 KB Output is correct
15 Correct 3911 ms 195784 KB Output is correct
16 Correct 9960 ms 196996 KB Output is correct
17 Correct 6 ms 764 KB Output is correct
18 Correct 6 ms 760 KB Output is correct
19 Correct 6 ms 760 KB Output is correct
20 Correct 6 ms 888 KB Output is correct
21 Correct 6 ms 888 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 6 ms 888 KB Output is correct
24 Correct 6 ms 888 KB Output is correct
25 Correct 6 ms 888 KB Output is correct
26 Correct 6 ms 888 KB Output is correct
27 Correct 93 ms 3320 KB Output is correct
28 Correct 6 ms 888 KB Output is correct
29 Correct 612 ms 2872 KB Output is correct
30 Correct 2033 ms 65284 KB Output is correct
31 Correct 8649 ms 194476 KB Output is correct
32 Correct 8677 ms 194684 KB Output is correct
33 Correct 2090 ms 62376 KB Output is correct
34 Correct 8618 ms 191132 KB Output is correct
35 Correct 2112 ms 62512 KB Output is correct
36 Correct 8706 ms 190880 KB Output is correct
37 Correct 2149 ms 67152 KB Output is correct
38 Correct 8750 ms 195104 KB Output is correct
39 Correct 6 ms 760 KB Output is correct
40 Correct 8793 ms 191148 KB Output is correct