이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#define f first
#define s second
using namespace std;
const short LIM = 174;
short n, m, st, ed;
//bool hv[30001];
int cnt, b[30001][180];
pair<short,short> a[30001];
vector<vector<pair<int,int>>> edge;
vector<int> dist;
vector<bool> vis;
deque<int> q;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
cnt = n-1;
for (short i = 0; i < n; i++) edge.push_back({});
for (short i = 1; i <= m; i++) {
cin >> a[i].f >> a[i].s;
//hv[a[i].f] = 1;
}
for (short i = 1; i <= m; i++) {
short u = a[i].f, v = a[i].s;
if (i == 1) st = u;
if (i == 2) ed = u;
if (v <= LIM) {
if (!b[u][v]) {
for (int j = u%v; j < n; j += v) {
b[j][v] = ++cnt;
edge.push_back({});
edge[cnt].push_back({j,0});
if (j != u%v) {
edge[cnt].push_back({cnt-1,1});
edge[cnt-1].push_back({cnt,1});
}
}
}
edge[u].push_back({b[u][v],0});
} else {
for (int j = u%v; j < n; j += v) {
++cnt;
edge.push_back({});
edge[cnt].push_back({j,0});
if (j == u) edge[u].push_back({cnt,0});
if (j != u%v) {
edge[cnt].push_back({cnt-1,1});
edge[cnt-1].push_back({cnt,1});
}
}
}
}
dist.resize(cnt+1);
vis.resize(cnt+1);
for (int i = 0; i <= cnt; i++) dist[i] = 1e9;
q.push_back(st);
dist[st] = 0;
while (q.size()) {
int u = q.front();
q.pop_front();
if (vis[u]) continue;
vis[u] = 1;
if (u == ed) {
cout << dist[ed] << endl;
return 0;
}
for (int i = 0; i < edge[u].size(); i++) {
if (dist[edge[u][i].f] > dist[u]+edge[u][i].s) {
dist[edge[u][i].f] = dist[u]+edge[u][i].s;
if (edge[u][i].s) q.push_back(edge[u][i].f);
else q.push_front(edge[u][i].f);
}
}
}
cout << -1 << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < edge[u].size(); 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... |