Submission #116503

#TimeUsernameProblemLanguageResultExecution timeMemory
116503roseanne_pcyJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
230 ms254172 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*180*2]; vector<int> adj[maxn*180*2]; bool ok(int x) { return 0<= x && x< n; } int N; void bfs(int s) { for(int i = 0; i< N+10; i++) dist[i] = 1e9; queue<int> q; dist[s] = 0; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v : adj[u]) { if(dist[v]> dist[u]+1) { dist[v] = dist[u]+1; q.push(v); } } } } int hom[maxn], mana[maxn]; int conv(int u, int md, int isleft) { if(isleft) return (half+1)*n+(md-1)*n+u; return md*n+u; } int main() { scanf("%d %d", &n, &m); // printf("%d %d\n", conv(0, 1, 0), conv(0, 1, 1)); for(int i = 0; i< m; i++) { scanf("%d %d", &hom[i], &mana[i]); } // printf("okay\n"); for(int i = 0; i< n; i++) { for(int md = 1; md<= half; md++) { if(ok(i+md)) { adj[conv(i, md, 0)].pb(i+md); adj[conv(i, md, 0)].pb(conv(i+md, md, 0)); } if(ok(i-md)) { adj[conv(i, md, 1)].pb(i-md); adj[conv(i, md, 1)].pb(conv(i-md, md, 1)); } } } for(int i = 0; i< m; i++) { int pw = mana[i]; if(pw> half) { int cur = hom[i]; while(cur< n) { int nxt = cur+pw; if(ok(nxt)) adj[cur].pb(nxt); cur = nxt; } cur = hom[i]; while(cur>= 0) { int nxt = cur-pw; if(ok(nxt)) adj[cur].pb(nxt); cur = nxt; } } else { int x = hom[i]; if(ok(x-pw)) { adj[x].pb(conv(x-pw, pw, 1)); adj[x].pb(x-pw); } if(ok(x+pw)) { adj[x].pb(conv(x+pw, pw, 0)); adj[x].pb(x+pw); } } } 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:54: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:58: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...