이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using ll = long long;
const int N=1<<17;
const ll INF=1e18;
ll dist[N];
bool vis[N];
int main(){
int l, n;
cin>>l>>n;
vector<pair<pair<int, int>, pair<int, int>> > V(n);
for(int i=0; i<n; ++i){
cin>>V[i].nd.st>>V[i].st.st>>V[i].st.nd>>V[i].nd.nd;
V[i].st.st--;
}
for(int i=0; i<n; i++){
if(V[i].st.st)dist[i]=INF;
else dist[i]=V[i].nd.nd;
}
for(int ii=0; ii<n; ii++){
int opt=0;
for(int j=0; j<n; j++){
//cout<<dist[j]<<" \n"[j==n-1];
if(!vis[j] && (vis[opt] || dist[j]<dist[opt]))opt=j;
}
vis[opt]=1;
if(V[opt].st.nd==l && dist[opt]!=INF){
cout<<dist[opt];
return 0;
}
for(int i=0; i<n; i++){
if(V[i].st.st+V[i].nd.st<=V[opt].st.nd+V[opt].nd.st
&& V[i].st.st-V[i].nd.st<=V[opt].st.nd-V[opt].nd.st){
if(dist[i]>V[i].nd.nd+dist[opt]){
dist[i]=V[i].nd.nd+dist[opt];
}
}
}
}
cout<<-1;
}
# | 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... |