이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define forin(i, a, b) for(int i = a; i <= b; ++i)
#define ii pair<int, int>
using namespace std;
const int N = 3e4 + 10;
int n, m;
int b[N], p[N], d[N];
vector<ii> adj[N];
void dijkstra(int s) {
priority_queue<ii, vector<ii>, greater<ii> > pq;
fill(d + 1, d + m + 1, 1e18);
pq.push({0, s});
d[s] = 0;
while(!pq.empty()) {
int kc, u; tie(kc, u) = pq.top();
pq.pop();
if(kc != d[u]) continue;
for(auto e : adj[u]) {
int w, v; tie(w, v) = e;
if(d[v] <= d[u] + w) continue;
d[v] = d[u] + w;
pq.push({d[v], v});
}
}
}
int main () {
cin.tie(0)->sync_with_stdio(0);
if(fopen("Task.inp","r")) {
freopen("Task.inp","r",stdin);
freopen("WA.out","w",stdout);
}
cin>>n>>m;
forin(i, 1, m) cin>>b[i]>>p[i];
forin(i, 1, m) forin(j, 1, m) if(i != j) {
bool ok = ((b[j] - b[i]) % p[i] == 0);
if(ok) {
int w = abs(b[j] - b[i]) / p[i];
adj[i].push_back({w, j});
}
}
dijkstra(1);
if(d[2] == 1e18) cout<<-1;
else cout<<d[2];
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen("Task.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("WA.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |