Submission #253981

# Submission time Handle Problem Language Result Execution time Memory
253981 2020-07-29T08:12:34 Z TadijaSebez Wall (CEOI14_wall) C++11
100 / 100
406 ms 25308 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ban(x,y) ban[(x)-(go[(x)][(y)]==0)][(y)-(go[(x)][(y)]==1)][go[(x)][(y)]&1]
const int N=405;
const ll inf=9e18;
ll dist[N][N],ans[N][N][4];
int w[N][N][2],has[N][N],go[N][N],ban[N][N][2];
int mv[4][2]={{1,0},{0,1},{-1,0},{0,-1}},blk[4][2]={{0,2},{0,1},{1,3},{2,3}};
int main(){
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)scanf("%i",&has[i][j]);
	for(int i=0;i<n;i++)for(int j=0;j<=m;j++)scanf("%i",&w[i][j][0]);
	for(int i=0;i<=n;i++)for(int j=0;j<m;j++)scanf("%i",&w[i][j][1]);
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)dist[i][j]=inf;
	dist[0][0]=0;
	priority_queue<array<ll,3>> pq;
	pq.push({0,0,0});
	while(pq.size()){
		int x=pq.top()[1],y=pq.top()[2];
		ll d=-pq.top()[0];
		pq.pop();
		if(dist[x][y]!=d)continue;
		for(int i=0;i<4;i++){
			int nx=x+mv[i][0],ny=y+mv[i][1];
			if(nx<0||nx>n||ny<0||ny>m)continue;
			ll now=d+w[nx-(i==0)][ny-(i==1)][i&1];
			if(dist[nx][ny]>now){
				dist[nx][ny]=now;
				go[nx][ny]=i;
				pq.push({-now,nx,ny});
			}
		}
	}
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(has[i][j]){
		int x=i,y=j;
		while(x||y){
			if(ban(x,y))
				break;
			ban(x,y)=1;
			int tmp=go[x][y];
			x-=mv[tmp][0];
			y-=mv[tmp][1];
		}
		ban[i][j][0]=ban[i][j+1][0]=ban[i][j][1]=ban[i+1][j][1]=1;
	}
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)for(int k=0;k<4;k++)ans[i][j][k]=inf;
	ans[0][0][1]=0;
	priority_queue<array<ll,4>> pq2;
	pq2.push({0,0,0,1});
	while(pq2.size()){
		int x=pq2.top()[1],y=pq2.top()[2],k=pq2.top()[3];
		ll d=-pq2.top()[0];
		pq2.pop();
		if(d!=ans[x][y][k])continue;
		if(x||y){
			if(x-1+k%2<0||x-1+k%2>=n||!ban[x-1+k%2][y][0]){
				if(ans[x][y][k^2]>d){
					ans[x][y][k^2]=d;
					pq2.push({-d,x,y,k^2});
				}
			}
			if(y-1+k/2<0||y-1+k/2>=m||!ban[x][y-1+k/2][1]){
				if(ans[x][y][k^1]>d){
					ans[x][y][k^1]=d;
					pq2.push({-d,x,y,k^1});
				}
			}
		}
		for(int i=0;i<4;i++){
			int nx=x+mv[i][0],ny=y+mv[i][1],nk=k^(i%2+1);
			if(nx<0||nx>n||ny<0||ny>m||k==blk[i][0]||k==blk[i][1])continue;
			ll now=d+w[nx-(i==0)][ny-(i==1)][i&1];
			if(ans[nx][ny][nk]>now){
				ans[nx][ny][nk]=now;
				pq2.push({-now,nx,ny,nk});
			}
		}
	}
	printf("%lld\n",ans[0][0][2]);
	return 0;
}

Compilation message

wall.cpp: In function 'int main()':
wall.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
wall.cpp:13:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++)for(int j=0;j<m;j++)scanf("%i",&has[i][j]);
                                          ~~~~~^~~~~~~~~~~~~~~~~
wall.cpp:14:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++)for(int j=0;j<=m;j++)scanf("%i",&w[i][j][0]);
                                           ~~~~~^~~~~~~~~~~~~~~~~~
wall.cpp:15:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<=n;i++)for(int j=0;j<m;j++)scanf("%i",&w[i][j][1]);
                                           ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
13 Correct 3 ms 1024 KB Output is correct
14 Correct 3 ms 1024 KB Output is correct
15 Correct 3 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1280 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1280 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 6004 KB Output is correct
2 Correct 55 ms 4736 KB Output is correct
3 Correct 50 ms 4984 KB Output is correct
4 Correct 58 ms 7924 KB Output is correct
5 Correct 78 ms 9208 KB Output is correct
6 Correct 64 ms 5752 KB Output is correct
7 Correct 167 ms 10480 KB Output is correct
8 Correct 152 ms 8952 KB Output is correct
9 Correct 125 ms 8952 KB Output is correct
10 Correct 164 ms 12648 KB Output is correct
11 Correct 184 ms 16100 KB Output is correct
12 Correct 41 ms 5496 KB Output is correct
13 Correct 146 ms 9336 KB Output is correct
14 Correct 198 ms 12656 KB Output is correct
15 Correct 265 ms 12024 KB Output is correct
16 Correct 254 ms 12728 KB Output is correct
17 Correct 367 ms 19168 KB Output is correct
18 Correct 406 ms 25308 KB Output is correct
19 Correct 359 ms 15212 KB Output is correct
20 Correct 268 ms 12728 KB Output is correct