Submission #235275

# Submission time Handle Problem Language Result Execution time Memory
235275 2020-05-27T14:51:36 Z Goolakh Portals (BOI14_portals) C++17
100 / 100
321 ms 28224 KB
/// Be Kind :)
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

/*				Bitch, where you when I was walkin'?
				Now I run the game, got the whole world talkin'				*/

/*				You never likes us anyway, fuck your friendship, I meant it */

/*				The Chanel or Balenciaga, Louis and Vuitton
				She know I got Fendi, Prada when I hit Milan				*/

/*				Niggas been counting me out
				I'm counting my bullets, I'm loading my clips
				I'm writing down names, I'm making a list					*/

/*				I ran away, I don't think I'm coming back home				*/

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e3+10, maxm=51, lg=23, mod=1e9+7, inf=1e18;

ll dx[]={1,0,-1,0};
ll dy[]={0,1,0,-1};

char bb[maxn][maxn];
ll ww[maxn][maxn],dis[maxn][maxn];
bool mk[maxn][maxn];
ll U[maxn][maxn],D[maxn][maxn],L[maxn][maxn],R[maxn][maxn];

priority_queue<pll,vector<pll>,greater<pll>> pq;
void midi(ll x,ll y,ll d){
	if(dis[x][y]>d) dis[x][y]=d, pq.push({dis[x][y],x*maxn+y});
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) ww[i][j]=min({i,j,n-i+1,m-j+1});
	deque<ll> q;
	ll sx,sy,ex,ey;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>bb[i][j];
			if(bb[i][j]=='S')      sx=i,sy=j, bb[i][j]='.';
			else if(bb[i][j]=='C') ex=i,ey=j, bb[i][j]='.';
			else if(bb[i][j]=='#'){
				ww[i][j]=0;
				q.pb(i*maxn+j);
			}
		}
	}
	while(!q.empty()){
		ll x=q.front()/maxn, y=q.front()%maxn; q.pop_front();
		for(int k:{0,1,2,3}){
			ll i=x+dx[k], j=y+dy[k];
			if(bb[i][j]=='.'){
				if(ww[i][j]>ww[x][y]+1) ww[i][j]=ww[x][y]+1, q.pb(i*maxn+j);
			}
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
		U[i][j]=(bb[i-1][j]=='.' ? U[i-1][j]:i*maxn+j);
		L[i][j]=(bb[i][j-1]=='.' ? L[i][j-1]:i*maxn+j);
	}
	for(int i=n;i>=1;i--)for(int j=m;j>=1;j--){
		D[i][j]=(bb[i+1][j]=='.' ? D[i+1][j]:i*maxn+j);
		R[i][j]=(bb[i][j+1]=='.' ? R[i][j+1]:i*maxn+j);
	}
	memset(dis,69,sizeof(dis));
	dis[sx][sy]=0;
	pq.push({dis[sx][sy],sx*maxn+sy});
	while(!pq.empty()){
		ll x=pq.top().S/maxn, y=pq.top().S%maxn; pq.pop();
		if(mk[x][y]) continue;
		for(int k:{0,1,2,3}){
			int i=x+dx[k], j=y+dy[k];
			if(bb[i][j]=='.') midi(i,j,dis[x][y]+1);
		}
		midi(R[x][y]/maxn,R[x][y]%maxn,dis[x][y]+ww[x][y]);
		midi(U[x][y]/maxn,U[x][y]%maxn,dis[x][y]+ww[x][y]);
		midi(L[x][y]/maxn,L[x][y]%maxn,dis[x][y]+ww[x][y]);
		midi(D[x][y]/maxn,D[x][y]%maxn,dis[x][y]+ww[x][y]);
	}
	cout<<dis[ex][ey];
	
	return 0;
}
















Compilation message

portals.cpp:34:54: warning: overflow in implicit constant conversion [-Woverflow]
 const ll maxn=1e3+10, maxm=51, lg=23, mod=1e9+7, inf=1e18;
                                                      ^~~~
portals.cpp: In function 'int main()':
portals.cpp:100:18: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout<<dis[ex][ey];
                  ^
portals.cpp:100:18: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
portals.cpp:87:30: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pq.push({dis[sx][sy],sx*maxn+sy});
                       ~~~~~~~^~~
portals.cpp:87:25: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pq.push({dis[sx][sy],sx*maxn+sy});
                       ~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4352 KB Output is correct
2 Correct 7 ms 4608 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 7 ms 4480 KB Output is correct
5 Correct 7 ms 4608 KB Output is correct
6 Correct 8 ms 4608 KB Output is correct
7 Correct 7 ms 4608 KB Output is correct
8 Correct 8 ms 4608 KB Output is correct
9 Correct 7 ms 4480 KB Output is correct
10 Correct 7 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4352 KB Output is correct
2 Correct 7 ms 4608 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 7 ms 4488 KB Output is correct
5 Correct 7 ms 4608 KB Output is correct
6 Correct 7 ms 4608 KB Output is correct
7 Correct 7 ms 4584 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 7 ms 5376 KB Output is correct
11 Correct 7 ms 5376 KB Output is correct
12 Correct 8 ms 5376 KB Output is correct
13 Correct 7 ms 5376 KB Output is correct
14 Correct 7 ms 4480 KB Output is correct
15 Correct 7 ms 5376 KB Output is correct
16 Correct 7 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4352 KB Output is correct
2 Correct 7 ms 4608 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 7 ms 4608 KB Output is correct
5 Correct 14 ms 8704 KB Output is correct
6 Correct 16 ms 8704 KB Output is correct
7 Correct 16 ms 8704 KB Output is correct
8 Correct 11 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4352 KB Output is correct
2 Correct 7 ms 4608 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 7 ms 4480 KB Output is correct
5 Correct 7 ms 4608 KB Output is correct
6 Correct 7 ms 4608 KB Output is correct
7 Correct 7 ms 4608 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5376 KB Output is correct
12 Correct 8 ms 5504 KB Output is correct
13 Correct 7 ms 5376 KB Output is correct
14 Correct 14 ms 8704 KB Output is correct
15 Correct 15 ms 8704 KB Output is correct
16 Correct 16 ms 8704 KB Output is correct
17 Correct 14 ms 8576 KB Output is correct
18 Correct 16 ms 8576 KB Output is correct
19 Correct 15 ms 8576 KB Output is correct
20 Correct 16 ms 8552 KB Output is correct
21 Correct 14 ms 8704 KB Output is correct
22 Correct 17 ms 8704 KB Output is correct
23 Correct 15 ms 8704 KB Output is correct
24 Correct 14 ms 8576 KB Output is correct
25 Correct 7 ms 4480 KB Output is correct
26 Correct 7 ms 5376 KB Output is correct
27 Correct 7 ms 4480 KB Output is correct
28 Correct 11 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4352 KB Output is correct
2 Correct 7 ms 4608 KB Output is correct
3 Correct 7 ms 4608 KB Output is correct
4 Correct 6 ms 4480 KB Output is correct
5 Correct 7 ms 4608 KB Output is correct
6 Correct 7 ms 4608 KB Output is correct
7 Correct 7 ms 4608 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 8 ms 5376 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 7 ms 5376 KB Output is correct
12 Correct 7 ms 5376 KB Output is correct
13 Correct 7 ms 5376 KB Output is correct
14 Correct 14 ms 8704 KB Output is correct
15 Correct 15 ms 8704 KB Output is correct
16 Correct 16 ms 8704 KB Output is correct
17 Correct 16 ms 8576 KB Output is correct
18 Correct 16 ms 8576 KB Output is correct
19 Correct 15 ms 8576 KB Output is correct
20 Correct 19 ms 8576 KB Output is correct
21 Correct 18 ms 8704 KB Output is correct
22 Correct 20 ms 8704 KB Output is correct
23 Correct 15 ms 8704 KB Output is correct
24 Correct 195 ms 27812 KB Output is correct
25 Correct 321 ms 26360 KB Output is correct
26 Correct 231 ms 26232 KB Output is correct
27 Correct 227 ms 26232 KB Output is correct
28 Correct 166 ms 28016 KB Output is correct
29 Correct 188 ms 28068 KB Output is correct
30 Correct 213 ms 28012 KB Output is correct
31 Correct 15 ms 8576 KB Output is correct
32 Correct 214 ms 26232 KB Output is correct
33 Correct 7 ms 4480 KB Output is correct
34 Correct 8 ms 5376 KB Output is correct
35 Correct 177 ms 27132 KB Output is correct
36 Correct 7 ms 4480 KB Output is correct
37 Correct 12 ms 8728 KB Output is correct
38 Correct 88 ms 27832 KB Output is correct
39 Correct 137 ms 28224 KB Output is correct