제출 #249218

#제출 시각아이디문제언어결과실행 시간메모리
249218rdd6584Jakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1088 ms84180 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int ,int> pii; // last를 기록하고. 이게 갱신되면 그것에 의한 갱신을 해줘야함. // 원래 여기에 속해 있던 애는 바로 이용할 수 있음... // 원래 있던 애 리스트... int md[30000]; char visit[30000]; unordered_map<int,int> dist[30000]; vector<int> v[30000]; int main() { int n, m; scanf("%d %d", &n, &m); int st, ed; for (int i = 0; i < m; i++) { int a,b; scanf("%d %d" ,&a, &b); v[a].push_back(b); if (i==0) st = a; else if (i==1) ed = a; } queue<pii> q; for (int i : v[st]) dist[st][i] = 0, q.push({st, i}); while (!q.empty()) { pii tv = q.front(); q.pop(); // printf("%d %d\n", tv.first, tv.second); if (tv.first == ed) return !printf("%d", dist[tv.first][tv.second]); int ne = tv.first-tv.second; int me = dist[tv.first][tv.second]; if (ne >= 0) { if (dist[ne].find(tv.second) == dist[ne].end()) { int flag = 0; if (!visit[ne]) { visit[ne] = 1; for (int i : v[ne]) { dist[ne][i] = me+1; q.push({ne, i}); if (i==tv.second) flag = 1; } } if (!flag) { q.push({ne, tv.second}); dist[ne][tv.second] = me + 1; } } } ne = tv.first+tv.second; if (ne < n) { if (dist[ne].find(tv.second) == dist[ne].end()) { int flag = 0; if (!visit[ne]) { visit[ne] = 1; for (int i : v[ne]) { dist[ne][i] = me+1; q.push({ne, i}); if (i==tv.second) flag = 1; } } if (!flag) { q.push({ne, tv.second}); dist[ne][tv.second] = me + 1; } } } } printf("-1"); }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d" ,&a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:19:9: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int st, ed;
         ^~
skyscraper.cpp:36:9: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (tv.first == ed) return !printf("%d", dist[tv.first][tv.second]);
         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...