Submission #116480

#TimeUsernameProblemLanguageResultExecution timeMemory
116480roseanne_pcyJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
5 ms2688 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; queue<int> q; q.push(s); dist[s] = 0; while(!q.empty()) { int u = q.front(); q.pop(); // printf("%d\n", u); 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); q.push(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); q.push(nxt); } cur = nxt; } } 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); q.push(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]); printf("%d\n", dist[hom[1]]); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:87: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:90: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...