이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=2000007;
ll n,m,k;
ll si,sj,ei,ej;
ll len[N];
set<int>jjj;
vector<int>jj;
unordered_map<int,int>d;
unordered_map<ll,vector<pair<ll,ll>>>g;
ll vertexNumber(int i, int j){
return j*n+i;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("Cinput.txt","r",stdin);
// freopen("Coutput.txt","w",stdout);
cin>>n>>si>>sj>>ei>>ej;
si--,sj--,ei--,ej--;
jjj.insert(0);
jjj.insert(sj);
jjj.insert(ej);
for(int i=0;i<n;i++){
cin>>len[i];
len[i]++;
jjj.insert(len[i]-1);
}
int cnt=0;
for(auto x:jjj){
jj.push_back(x);
d[x]=cnt;
cnt++;
}
for(int i=0;i<n;i++){
for(int j=0;j<jj.size();j++){
ll v=vertexNumber(i,j);
if(jj[j]>=len[i])break;
// RIGHT
if(j!=jj.size()-1&&jj[j+1]<len[i]){
g[v].push_back({vertexNumber(i,j+1),jj[j+1]-jj[j]});
}
else if(i!=n-1){
g[v].push_back({vertexNumber(i+1,0),1});
}
// LEFT
if(j!=0){
g[v].push_back({vertexNumber(i,j-1),jj[j]-jj[j-1]});
}
else if(i!=0){
g[v].push_back({vertexNumber(i-1,d[len[i-1]-1]),1});
}
// UP
if(i!=0&&jj[j]<len[i-1]){
g[v].push_back({vertexNumber(i-1,j),1});
}
else if(i!=0){
g[v].push_back({vertexNumber(i-1,d[len[i-1]-1]),1});
}
// DOWN
if(i!=n-1&&jj[j]<len[i+1]){
g[v].push_back({vertexNumber(i+1,j),1});
}
else if(i!=n-1){
g[v].push_back({vertexNumber(i+1,d[len[i+1]-1]),1});
}
}
}
// for(auto x:jj){
// cout<<x<<" ";
// }
// cout<<endl;
// for(int i=0;i<N;i++){
// if(!g[i].empty()){
// cout<<i<<": ";
// for(auto e:g[i]){
// cout<<"{"<<e.ff<<", "<<e.ss<<"}, ";
// }
// cout<<endl;
// }
// }
priority_queue<pair<ll,ll>>q;
vector<ll>dist(N, INF);
ll start=vertexNumber(si,d[sj]);
// cout<<start<<endl;
q.push({0,start});
dist[start]=0;
// cout<<"OK"<<endl;
while(!q.empty()){
ll v=q.top().ss;
ll w=-q.top().ff;
// cout<<v<<" "<<w<<endl;
q.pop();
if(dist[v]==w){
for(auto e:g[v]){
ll to=e.ff;
ll d=e.ss;
if(dist[to]>dist[v]+d){
dist[to]=dist[v]+d;
// cout<<to<<" "<<dist[to]<<endl;
q.push({-dist[to],to});
}
}
}
}
// cout<<vertexNumber(ei,d[ej])<<endl;
cout<<dist[vertexNumber(ei,d[ej])]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int j=0;j<jj.size();j++){
| ~^~~~~~~~~~
Main.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | if(j!=jj.size()-1&&jj[j+1]<len[i]){
| ~^~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |