Submission #116486

#TimeUsernameProblemLanguageResultExecution timeMemory
116486roseanne_pcyJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1081 ms104124 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") using namespace std; #define X first #define Y second #define pb push_back typedef pair<int, int> ii; typedef long long ll; const int maxn = 3e4+5; const int half = 173; int n, m; int dist[maxn]; set<int> unvis[180][180]; vector<int> png[maxn]; bool good(int x) { return 0<= x && x< n; } void bfs(int s) { for(int i = 0; i< n; i++) dist[i] = 1e9; priority_queue<pair<int, int> > pq; pq.push(ii(0, s)); dist[s] = 0; while(!pq.empty()) { auto kk = pq.top(); pq.pop(); int u = kk.Y, d = -kk.X; for(int i = 1; i<= half; i++) unvis[i][u%i].erase(u); if(d> dist[u]) continue; for(int pw : png[u]) { if(pw> half) { int cur = u; int w = 1; while(cur< n) { int nxt = cur+pw; if(good(nxt) && dist[nxt]> w+dist[u]) { dist[nxt] = w+dist[u]; // for(int i = 1; i<= half; i++) unvis[i][nxt%i].erase(nxt); pq.push(ii(-dist[nxt], nxt)); } w++; cur = nxt; } cur = u; w = 1; while(cur>= 0) { int nxt = cur-pw; if(good(nxt) && dist[nxt]> w+dist[u]) { dist[nxt] = w+dist[u]; // for(int i = 1; i<= half; i++) unvis[i][nxt%i].erase(nxt); pq.push(ii(-dist[nxt], nxt)); } cur = nxt; w++; } } else { for(int nxt : unvis[pw][u%pw]) { // if(u == 4) printf("go %d\n", nxt); if(dist[nxt]> abs(u-nxt)/pw+dist[u]) { dist[nxt] = abs(u-nxt)/pw+dist[u]; // for(int i = 1; i<= half; i++) unvis[i][nxt%i].erase(nxt); pq.push(ii(-dist[nxt], nxt)); } } unvis[pw][u%pw].clear(); } } } } int hom[maxn], mana[maxn]; int main() { scanf("%d %d", &n, &m); for(int i = 0; i< m; i++) { scanf("%d %d", &hom[i], &mana[i]); png[hom[i]].pb(mana[i]); } for(int md = 1; md<= half; md++) { for(int i = 0; i< n; i++) { unvis[md][i%md].insert(i); } } // printf("okay\n"); bfs(hom[0]); if(dist[hom[1]] == 1e9) printf("-1\n"); else printf("%d\n", dist[hom[1]]); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:90: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:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &hom[i], &mana[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...