# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
820174 | lprochniak | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 55 ms | 34776 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define MAX 30009
#define pb push_back
#define st first
#define nd second
int n,m;
vector<int> p[MAX];
struct Node{
int v;
int waga;
};
vector<Node> edges[MAX];
int wyn[MAX];
void dijkstra(int s){
priority_queue<pair<int,int>> q;
q.push({0,s});
while(!q.empty()){
pair<int,int> t = q.top();
q.pop();
t.st = -t.st;
for(auto x:edges[t.nd]){
if(t.st+x.waga<wyn[x.v]){
wyn[x.v] = t.st + x.waga;
q.push({-wyn[x.v],x.v});
}
}
}
}
int main(){
cin>>n>>m;
memset(p,0,sizeof p);
int whereZero,whereOne;
for(int i=0;i<m;i++){
int b,pwr;
cin>>b>>pwr;
p[b].pb(pwr);
if(i == 0)
whereZero = b;
else if(i == 1)
whereOne = b;
}
for(int i=0;i<n;i++){
if(p[i].empty()) continue;
for(auto pwr:p[i]){
int idx = i-pwr;
int ile = 1;
while(idx>=0){
edges[i].pb({idx,ile});
idx-=pwr,ile++;
}
idx = i+pwr;
ile = 1;
while(idx<n){
edges[i].pb({idx,ile});
idx+=pwr,ile++;
}
}
}
for(int i=1;i<n;i++){
wyn[i] = 1000000000;
}
dijkstra(whereZero);
if(wyn[whereOne] == 1000000000){
cout<<"-1\n";
} else
cout<<wyn[whereOne]<<"\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |