제출 #158239

#제출 시각아이디문제언어결과실행 시간메모리
158239AkashiJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1064 ms71124 KiB
#include <bits/stdc++.h> using namespace std; struct usu{ int x, y, l; }; int sgn[] = {-1, 1}; int n, m, pos; bool ok = false; vector <int> v[30005]; queue <usu> q; unordered_map <int, int> d[30005]; void f(int x, int y, int l){ for(int k = 0; k <= 1 ; ++k){ int nx = x + y * sgn[k]; if(nx < 0 || nx > n) continue ; if(d[nx][y] == 0){ if(nx == pos){ printf("%d", l); exit(0); } d[nx][y] = l + 1; q.push({nx, y, l + 1}); } } } int main() { scanf("%d%d", &n, &m); int x2, x, y; scanf("%d%d", &x, &y); d[x][y] = 1; x2 = x; q.push({x, y, 1}); scanf("%d%d", &x, &y); v[x].push_back(y); pos = x; if(pos == x2){ printf("0"); return 0; } for(int i = 3; i <= m ; ++i){ scanf("%d%d", &x, &y); v[x].push_back(y); } while(!q.empty()){ int x = q.front().x, y = q.front().y, l = q.front().l; q.pop(); f(x, y, l); for(auto it : v[x]) f(x, it, l); } printf("-1"); return 0; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:32: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:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#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...