이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
#define see(x) cout<<#x<<"="<<x<<endl;
#define endl "\n"
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
const int N = 30005;
const int INF = 1e9;
int n, m, b[N], p[N], d[2005], used[2005];
vector <pair <int, int>> g[2005];
priority_queue <pair <int, int>> q;
vector <int> mp[2005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
cin >> n >> m;
for (int i = 0; i < m; i ++) {
cin >> b[i] >> p[i];
mp[b[i]].push_back(i);
}
for (int i = 0; i < m; i ++) {
for (int j = 0; j < n; j ++) {
for (auto k: mp[j]) {
if (k == i) continue;
if (abs(b[k] - b[i]) % p[i] == 0) g[b[i]].push_back({b[k], abs(b[k] - b[i]) / p[i]});
}
}
/*
for (int j = b[i] - p[i]; j >= 0; j -= p[i]) {
for (auto k: mp[j]) {
if (k == i) continue;
if (abs(b[k] - b[i]) % p[i] == 0) g[i].push_back({k, abs(b[k] - b[i]) / p[i]});
}
}
*/
}
for (int i = 0; i < n; i ++) {
d[i] = INF;
}
d[b[0]] = 0;
q.push({0, b[0]});
while (!q.empty()) {
int v = q.top().second;
q.pop();
if (used[v]) continue;
used[v] = 1;
for (auto i: g[v]) {
if (d[i.first] > d[v] + i.second) {
d[i.first] = d[v] + i.second;
q.push({-d[i.first], i.first});
}
}
}
if (d[b[1]] == INF) d[b[1]] = -1;
cout << d[b[1]] << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp:8: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
8 | #pragma GCC optimization ("O3")
|
skyscraper.cpp:9: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
9 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |