Submission #695150

#TimeUsernameProblemLanguageResultExecution timeMemory
695150Farhan_HYJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
13 ms23824 KiB
#include <bits/stdc++.h> #define int long long #define float double #define pb push_back #define F first #define S second #define T int t; cin >> t; while(t--) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; /// Benzema is the best player in the world const int N = 1e6 + 6; const int M = 1e3 + 3; const int mod = 1e9 + 7; const int inf = 1e9; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int LOG = 28; int n, m; int p[N], dist[N]; vector<pair<int, int>> adj[N]; priority_queue<pair<int, int>> q; bool vis[N]; void dij() { for(int i = 1; i <= n; i++) dist[i] = inf; q.push({0, 1}); dist[1] = 0; while(!q.empty()) { int u = q.top().S; q.pop(); if (vis[u]) continue; vis[u] = 1; for(auto x: adj[u]) { if (dist[x.F] > dist[u] + x.S) dist[x.F] = dist[u] + x.S, q.push({-dist[x.F], x.F}); } } } main() { IOS cin >> n >> m; for(int i = 1; i <= m; i++) { int b; cin >> b >> p[i]; b++; int j = b - p[i], cnt = 1; while(j >= 1) { adj[b].push_back({j, cnt++}); j -= p[i]; } cnt = 1, j = b + p[i]; while(j <= n) { adj[b].push_back({j, cnt++}); j += p[i]; } } dij(); if (dist[2] == inf) dist[2] = -1; cout << dist[2]; }

Compilation message (stderr)

skyscraper.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main() {
      | ^~~~
#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...