Submission #108873

#TimeUsernameProblemLanguageResultExecution timeMemory
108873kuroniJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
34 ms25208 KiB
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <algorithm> #define fi first #define se second using namespace std; const int N = 50005, D = 250, MX = 1E6 + 5, INF = 1E9 + 7; int n, m, d, b, p, st, en, dis[N][D]; vector<int> dif[N]; vector<pair<int, int>> ve[MX]; void mini(pair<int, int> u, int v) { if (dis[u.fi][u.se] > v) { dis[u.fi][u.se] = v; ve[v].push_back(u); } } void dijkstra() { for (int i = 0; i < n; i++) for (int j = 0; j < d; j++) dis[i][j] = INF; dis[st][0] = 0; ve[0].push_back({st, 0}); for (int i = 0; i < MX; i++) while (!ve[i].empty()) { pair<int, int> u = ve[i].back(); ve[i].pop_back(); mini({u.fi, 0}, i); if (u.se == 0) { for (int &v : dif[u.fi]) mini({u.fi, v}, i); } else if (u.se < d) { if (u.fi + u.se < n) mini({u.fi + u.se, u.se}, i + 1); if (u.fi - u.se >= 0) mini({u.fi - u.se, u.se}, i + 1); } else { for (int j = u.fi % u.se; j < n; j += u.se) mini({j, u.se}, i + abs(u.fi - j) / u.se + i); } } printf("%d\n", dis[en][0] == INF ? -1 : dis[en][0]); } int main() { scanf("%d%d", &n, &m); d = sqrt(n - 1) + 1; for (int i = 0; i < m; i++) { scanf("%d%d", &b, &p); if (i == 0) st = b; else if (i == 1) en = b; dif[b].push_back(p); } for (int i = 0; i < n; i++) { sort(dif[i].begin(), dif[i].end()); dif[i].erase(unique(dif[i].begin(), dif[i].end()), dif[i].end()); } dijkstra(); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:59: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:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &b, &p);
         ~~~~~^~~~~~~~~~~~~~~~
#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...