이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAXN = 3e4 + 5;
ll n, m, ans = -1, awal, tujuan;
vector<ll> baris[MAXN];
// bool visited[MAXN][MAXN];
map<pll, bool> visited;
void bfs() {
queue<pair<pll, ll>> que;
// {{Idx Baris, Lompat}, Dist}
for (int i = 0; i < baris[awal].size(); ++i)
{
que.push({{awal, baris[awal][i]}, 0});
}
while(!que.empty()) {
pair<pll, ll> now = que.front();
// {{Idx Baris, Lompat}, Dist}
que.pop();
if (visited[now.first])
{
continue ;
}
visited[now.first] = true;
if (now.first.first == tujuan)
{
ans = now.second;
return ;
}
ll lompat = now.first.second;
ll nxt = now.first.first + lompat;
if (nxt < n && !visited[{nxt, lompat}])
{
que.push({{nxt, lompat}, now.second+1});
}
nxt = now.first.first - lompat;
if (nxt >= 0 && !visited[{nxt, lompat}])
{
que.push({{nxt, lompat}, now.second+1});
}
vector<ll> barisNow = baris[now.first.first];
for (int i = 0; i < barisNow.size(); ++i)
{
lompat = barisNow[i];
nxt = now.first.first + lompat;
if (nxt < n && !visited[{nxt, lompat}])
{
que.push({{nxt, lompat}, now.second+1});
}
nxt = now.first.first - lompat;
if (nxt >= 0 && !visited[{nxt, lompat}])
{
que.push({{nxt, lompat}, now.second+1});
}
}
}
}
int main(){
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
ll tmpa, tmpb;
cin >> tmpa >> tmpb;
baris[tmpa].push_back(tmpb);
if (i == 0) {
awal = tmpa;
} else if (i == 1) {
tujuan = tmpa;
}
}
bfs();
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void bfs()':
skyscraper.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < baris[awal].size(); ++i)
| ~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < barisNow.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... |