Submission #249202

#TimeUsernameProblemLanguageResultExecution timeMemory
249202hunni10Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1084 ms2092 KiB
#include<stdio.h> #include<algorithm> #include<vector> #include<set> #include<map> #include<bitset> #include<math.h> #include<string.h> #include<queue> #include<list> #include<time.h> #include<assert.h> #include<unordered_set> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef pair<ll, int> pli; int n, m; int b[30000]; int p[30000]; int shortest[30000]; bool visited[30000] = {0, }; bool inSorted[30000] = { 0, }; set<pii> sorted; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", b + i, p + i); } for (int i = 0; i < m; i++) { shortest[i] = 0x7FFFFFFF; } shortest[0] = 0; inSorted[0] = true; sorted.insert({ 0, 0 }); while (true) { if (sorted.empty()) { printf("-1"); break; } pii now = *sorted.begin(); if (now.second == 1) { printf("%d", now.first); break; } visited[now.second] = true; for (int i = 0; i < m; i++) { if (visited[i]) continue; if ((b[i] - b[now.second]) % p[now.second] == 0) { int times = (b[i] - b[now.second]) / p[now.second]; if (times < 0) times = -times; times += now.first; if (times < shortest[i]) { if (inSorted) { sorted.erase({ shortest[i], i }); } shortest[i] = times; sorted.insert({ shortest[i], i }); inSorted[i] = true; } } } sorted.erase(sorted.begin()); } }

Compilation message (stderr)

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