이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2","popcnt","rdrnd","bmi2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=507, INF=1e9+7;
string T[LIM];
int odl[LIM*LIM];
vector<pair<int,int>>V[LIM*LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
rep(i, n) cin >> T[i];
rep(i, n) rep(j, m) if(T[i][j]!='X') {
int ile=0;
if(T[i][j]=='E') ile=3;
if(T[i][j]=='S') ile=2;
if(T[i][j]=='W') ile=1;
if(i>0) V[i*m+j].pb({(i-1)*m+j, ile});
ile=(ile+1)%4;
if(j<m-1) V[i*m+j].pb({i*m+j+1, ile});
ile=(ile+1)%4;
if(i<n-1) V[i*m+j].pb({(i+1)*m+j, ile});
ile=(ile+1)%4;
if(j>0) V[i*m+j].pb({i*m+j-1, ile});
}
rep(i, n*m) odl[i]=INF;
priority_queue<pair<int,int>>q;
q.push({0, 0});
while(!q.empty()) {
int p=q.top().nd, o=-q.top().st; q.pop();
if(odl[p]<o) continue;
odl[p]=o;
for(auto i : V[p]) if(odl[i.st]>odl[p]+i.nd) {
q.push({-odl[p]-i.nd, i.st});
}
}
cout << (odl[n*m-1]==INF?-1:odl[n*m-1]) << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
adventure.cpp:2: warning: ignoring '#pragma GCC option' [-Wunknown-pragmas]
2 | #pragma GCC option("arch=native","tune=native","no-zero-upper")
|
# | 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... |