Submission #158237

#TimeUsernameProblemLanguageResultExecution timeMemory
158237AkashiJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1079 ms67188 KiB
#include <bits/stdc++.h> using namespace std; struct usu{ int x, y, l; }; int sgn[] = {-1, 1}; int n, m; vector <int> v[30005]; queue <usu> q; 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){ d[nx][y] = l + 1; q.push({nx, y, l + 1}); } } } int main() { scanf("%d%d", &n, &m); int x, y, pos; scanf("%d%d", &x, &y); d[x][y] = 1; q.push({x, y, 1}); scanf("%d%d", &x, &y); v[x].push_back(y); pos = x; 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; if(x == pos){ printf("%d", l - 1); return 0; } q.pop(); f(x, y, l); for(auto it : v[x]) f(x, it, l); } printf("-1"); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:27: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:30: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:34: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:38: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...