Submission #334950

#TimeUsernameProblemLanguageResultExecution timeMemory
334950SaynaaJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1097 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], v, tmp, u, x; 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]); } for(int i = 0;i < n; i ++) dis[i] = INT_MAX; dis[b[0]] = 0; priority_queue< pair< int, int> > q; q.push({0, b[0]}); while( q.size() ){ v = q.top().second, tmp = -q.top().first; q.pop(); if( dis[v] < tmp || dis[v] == INT_MAX) continue; for(int i = 0; i < adj[v].size(); i ++){ u = adj[v][i]; x = 1; for(int i = v + u; i < n; i += u){ if( dis[i] <= dis[v] + x){ x ++; continue; } dis[i] = dis[v] + x, q.push({-dis[i], i}), x ++; } x = 1; for(int i = v - u; i >= 0; i -= u){ if( dis[i] <= dis[v] + x){ x ++; continue; } dis[i] = dis[v] + x, q.push({-dis[i], i}), x ++; } } } printf("%d", (dis[b[1]] != INT_MAX ? dis[b[1]] : -1 )); return 0; }

Compilation message (stderr)

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