Submission #477319

#TimeUsernameProblemLanguageResultExecution timeMemory
477319KienTranJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1093 ms161816 KiB
#include <bits/stdc++.h> using namespace std; const int O = 3e4 + 5; const int N = 2e3 + 5; const int inf = 1e9; int n, m, Max, b[O], d[O], p[O], dd[O], c[N][N]; vector <int> g[N][N]; main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; ++ i){ cin >> b[i] >> p[i]; Max = max(Max, p[i]); int x = p[i]; int y = b[i] % p[i]; dd[i] = c[x][y]; //c[x][y] = true; } dd[2] = false; for (int i = 1; i <= m; ++ i){ if (dd[i] == 0){ for (int j = 1; j <= Max; ++ j) g[j][b[i] % j].push_back(i); } } //for (int i : g[2][0]) cout << "have " << i << endl; for (int i = 1; i <= m; ++ i) d[i] = inf; d[1] = 0; priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> q; q.push(make_pair(0, 1)); while (q.size()){ int u = q.top().second; int du = q.top().first; q.pop(); if (du != d[u]) continue; for (int v : g[p[u]][b[u] % p[u]]){ if (d[v] > d[u] + abs(b[u] - b[v]) / p[u]){ d[v] = d[u] + abs(b[u] - b[v]) / p[u]; q.push(make_pair(d[v], v)); } } } if (d[2] >= inf) cout << -1; else cout << d[2]; }

Compilation message (stderr)

skyscraper.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | 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...