제출 #116495

#제출 시각아이디문제언어결과실행 시간메모리
116495roseanne_pcyJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
330 ms254328 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; 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); N = (2*half+1)*n-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)); if(ok(x+pw)) adj[x].pb(conv(x+pw, pw, 0)); } } bfs(hom[0]); if(dist[hom[1]] == 1e9) printf("-1\n"); else printf("%d\n", dist[hom[1]]); }

컴파일 시 표준 에러 (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...