Submission #25653

#TimeUsernameProblemLanguageResultExecution timeMemory
25653gabrielsimoesJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1000 ms3648 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 3e4+10; const ll INF = ll(MAXN)*ll(MAXN)*ll(MAXN); int N, M, X, Y; vector<int> v[MAXN]; bool ok[MAXN]; ll d[MAXN]; void dijkstra() { memset(d, -1, sizeof(d)); d[X] = 0; while (true) { int cur = -1; for (int i = 0; i < N; i++) if (d[i] != -1 && !ok[i] && (cur == -1 || d[i] < d[cur])) cur = i; if (cur == -1) return; ok[cur] = true; for (int dx : v[cur]) { int cnt = (N - cur)/dx; int i = cur + dx*cnt; while (i >= 0) { if (d[i] == -1 || d[cur] + abs(cnt) < d[i]) d[i] = d[cur] + abs(cnt); i -= dx; cnt--; } } } } int main() { scanf("%d %d", &N, &M); for (int i = 0,a,b; i < M; i++) { scanf("%d %d", &a, &b); if (i == 0) X = a; else if (i == 1) Y = a; if (b != 0) v[a].push_back(b); } for (int i = 0; i < N; i++) sort(v[i].begin(), v[i].end()), v[i].resize(unique(v[i].begin(), v[i].end()) - v[i].begin()); dijkstra(); printf("%lld\n", d[Y]); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
skyscraper.cpp:41:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
                         ^
#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...