제출 #334947

#제출 시각아이디문제언어결과실행 시간메모리
334947SaynaaJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1091 ms9448 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 3e5 + 2; int n, m, b[MAXN], p[MAXN], dis[MAXN]; vector< int > adj[MAXN]; int main(){ scanf("%d%d", &n, &m); for(int i = 0; i < m; i ++){ scanf("%d%d", &b[i], &p[i]); adj[b[i]].push_back(p[i]); } fill(dis, dis + n, INT_MAX/2); dis[b[0]] = 0; priority_queue< pair< int, int> > q; q.push({0, b[0]}); while( q.size() ){ int v = q.top().second, tmp = -q.top().first; q.pop(); if( dis[v] < tmp || dis[v] == INT_MAX/2) continue; for(int i = 0; i < adj[v].size(); i ++){ int u = adj[v][i]; int x = 1; for(int i = v + u; i < n; i += u){ x ++; if( dis[i] <= dis[v] + x - 1) continue; dis[i] = dis[v] + x - 1, q.push({-dis[i], i}); } x = 1; for(int i = v - u; i >= 0; i -= u){ x ++; if( dis[i] <= dis[v] + x - 1) continue; dis[i] = dis[v] + x - 1, q.push({-dis[i], i}); } } } printf("%d", (dis[b[1]] != INT_MAX/2 ? dis[b[1]] : -1 )); return 0; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0; i < adj[v].size(); i ++){
      |                  ~~^~~~~~~~~~~~~~~
skyscraper.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |   scanf("%d%d", &b[i], &p[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...