이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define endl "\n"
#define ll long long
#define pb push_back
#define p push
#define f first
#define s second
ll int fark[5][5];
int main(){
lalala;
int n,m;
cin>>n>>m;
ll int uzak[n][m],arr[n][m];
for(int i=0;i<n;i++){
string str;cin>>str;
for(int j=0;j<str.size();j++){
uzak[i][j]=1000000000000000000;
if(str[j]=='E')arr[i][j]=1;
if(str[j]=='S')arr[i][j]=2;
if(str[j]=='W')arr[i][j]=3;
if(str[j]=='N')arr[i][j]=4;
if(str[j]=='X')arr[i][j]=0;
}
}
fark[0][1]=fark[0][2]=fark[0][3]=fark[0][4]=1000000000000000000;
fark[1][0]=fark[2][0]=fark[3][0]=fark[4][0]=1000000000000000000;
fark[1][2]=1;fark[1][3]=2;fark[1][4]=3;
fark[2][1]=3;fark[2][3]=1;fark[2][4]=2;
fark[3][1]=2;fark[3][2]=3;fark[3][4]=1;
fark[4][1]=1;;fark[4][2]=2;fark[4][3]=3;
priority_queue<pair<int,pair<int,int>>> pq;
pq.p({0,{0,0}});
while(pq.size()){
ll int deg=pq.top().f, x=pq.top().s.f, y=pq.top().s.s;
pq.pop();
uzak[x][y]=deg;
int kim=arr[x][y];
if(kim==0)continue;
if(x!=0&&uzak[x-1][y]>deg+fark[kim][4])pq.p({deg+fark[kim][4],{x-1,y}});
if(x!=n-1&&uzak[x+1][y]>deg+fark[kim][2])pq.p({deg+fark[kim][2],{x+1,y}});
if(y!=0&&uzak[x][y-1]>deg+fark[kim][3])pq.p({deg+fark[kim][3],{x,y-1}});
if(y!=m-1&&uzak[x][y+1]>deg+fark[kim][1])pq.p({deg+fark[kim][1],{x,y+1}});
}
if(uzak[n-1][m-1]==1000000000000000000)uzak[n-1][m-1]=-1;
cout<<uzak[n-1][m-1]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
adventure.cpp: In function 'int main()':
adventure.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int j=0;j<str.size();j++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |