답안 #494592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494592 2021-12-15T19:19:24 Z uncripted Awesome Arrowland Adventure (eJOI19_adventure) C++11
10 / 100
1 ms 396 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
long long n,m;
vector<pair< long long, long long> > adj[4000];

	char a[505][505];
char c[4]={'N','E','S','W'};
bool bound(long long x,long long y){

	if(x<0 || y<0 || x>=n || y>=m){
		return 0;
	}
	return 1;
}
long long dp[505][505];
long long dif(char x, char y){
	long long ix=0,iy=0;
	if(x=='X'){
		return 1e9;
	}
	for(long long i=0; i<4; i++){
	
		if(c[i]==x){
			ix=i;
		}
	}
	for(long long i=0; i<4; i++){
		if(c[i]==y){
			iy=i;
		}
	}
	if(ix<=iy){
		return iy-ix;
	}else{
		return 4-ix+iy;
	}
}
void solve(){

	priority_queue<pair<long long, pair<long long,long long> > > q;
	

	dp[0][0]=0;
	q.push({0,{0,0}});
	while(q.size()!=0){
		
		pair<long long,long long> te=q.top().s;
		long long x=te.f;
		long long y=te.s;
		if(dp[x][y]!=(q.top().f)){
			q.pop();
			continue;
		}
	
		/*
		if(vis[te.s]==true){
			q.pop();
			continue;
		}*/
		q.pop();
	long long t1=dp[x][y]+dif(a[x][y], 'W');
	long long t2=dp[x][y]+dif(a[x][y], 'N');
	long long t3=dp[x][y]+dif(a[x][y], 'S');
	long long t4=dp[x][y]+dif(a[x][y], 'E');
	if(bound(x,y-1)){
		if(t1<dp[x][y-1]){
			dp[x][y-1]=t1;
			//	cout<<x<<" "<<y-1<<" dp "<<dp[x][y-1]<<endl;
			q.push({-t1, {x,y-1}});
		}
	}
	if(bound(x-1,y)){
		if(t2<dp[x-1][y]){
			dp[x-1][y]=t2;
			q.push({-t2, {x-1,y}});
			//	cout<<x-1<<" "<<y<<" dp "<<dp[x-1][y]<<endl;
		}
	}
	if(bound(x+1,y)){
		if(t3<dp[x+1][y]){
			dp[x+1][y]=t3;
			q.push({-t3, {x+1,y}});
			//	cout<<x+1<<" "<<y<<" dp "<<dp[x+1][y]<<endl;
		}
	}
	if(bound(x,y+1)){
		if(t4<dp[x][y+1]){
			dp[x][y+1]=t4;
			q.push({-t4, {x,y+1}});
			//	cout<<x<<" "<<y+1<<" dp "<<dp[x][y+1]<<endl;
		}
	}
		
	}
	
	if(dp[n-1][m-1]>=1e9){
		cout<<"-1";
		
	}else{
		cout<<dp[n-1][m-1];
	}

	

	
}
int main(){
	cin>>n>>m;
	
 for (long long i = 0; i < n; i++){
 	for (long long j = 0; j < m; j++){
        	cin >> a[i][j];
			dp[i][j] = 1e9;
		}
 }
 solve();
        
          
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Incorrect 1 ms 396 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Incorrect 1 ms 396 KB Output isn't correct
13 Halted 0 ms 0 KB -