답안 #494584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494584 2021-12-15T18:55:40 Z uncripted Awesome Arrowland Adventure (eJOI19_adventure) C++11
0 / 100
1 ms 384 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,iy;
	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;
		}
	}
		
	}
	
	
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();
        
          
}

Compilation message

adventure.cpp: In function 'long long int dif(char, char)':
adventure.cpp:36:13: warning: 'iy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |   return iy-ix;
      |             ^~
adventure.cpp:36:13: warning: 'ix' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -