이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 3e4+5;
vector< vector < pair<int, int> > > adj(MAXN);
vector< vector < int > > doges(MAXN);
int dp[MAXN];
//map< pair<int, int>, bool > done;
map< pair<int, int>, int> max_road;
bool visited[MAXN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int goal, begin;
for(int i = 0; i < m; i++)
{
pair<int, int> temp;
cin >> temp.first >> temp.second;
if(i == 1)
goal = temp.first;
else if(i == 0)
begin = temp.first;
doges[temp.first].push_back(temp.second);
}
for(int i = 0; i <= n; i++) {
dp[i] = 1e9;
//visited[i] = false;
}
//visited[begin] = false;
dp[begin] = 0;
//set< pair<int, int> > curr;
//curr.insert({0, begin});
int ans = 1e9;
for(int i = 0; i < n; i++)
{
int v = -1;
for (int j = 0; j < n; j++) {
if (!visited[j] && (v == -1 || dp[j] < dp[v]))
v = j;
}
if (dp[v] == 1e9)
break;
visited[v] = true;
for(int temp : doges[v]) {
int currNode = v + temp;
int cnt = 1;
while(currNode < n)
{
int val = max_road[{v, currNode}];
if(val == 0 || val > cnt)
{
//adj[v].erase({val, currNode});
max_road[{v, currNode}] = cnt;
//adj[v].insert({cnt, currNode});
}
//if(curr == 4)
//cout << temp.first << "\n";
cnt++;
currNode += temp;
}
currNode = v - temp;
cnt = 1;
while(currNode >= 0)
{
int val = max_road[{v, currNode}];
if(val == 0 || val > cnt)
{
//adj[v].erase({val, currNode});
max_road[{v, currNode}] = cnt;
//adj[v].insert({cnt, currNode});
}
//if(curr == 4)
//cout << temp.first << "\n";
cnt++;
currNode -= temp;
}
}
for(int to = 0; to < n; to++)
{
int len = max_road[{v, to}];
if(len != 0)
{
if (dp[v] + len < dp[to]) {
dp[to] = dp[v] + len;
}
}
}
for (auto edge : adj[v]) {
int to = edge.second;
int len = edge.first;
if (dp[v] + len < dp[to]) {
dp[to] = dp[v] + len;
}
}
adj[v].clear();
}
ans = dp[goal];
if(ans >= 1e9)
ans = -1;
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:15: warning: 'begin' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | dp[begin] = 0;
| ~~~~~~~~~~^~~
skyscraper.cpp:117:9: warning: 'goal' may be used uninitialized in this function [-Wmaybe-uninitialized]
117 | ans = dp[goal];
| ~~~~^~~~~~~~~~
# | 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... |