제출 #116484

#제출 시각아이디문제언어결과실행 시간메모리
116484roseanne_pcyJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
6 ms3072 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; 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; for(int i = 1; i<= half; i++) unvis[i][s%i].erase(s); 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; 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); q.push(nxt); } } unvis[pw][u%pw].clear(); } } } } int hom[maxn], mana[maxn]; int main() { scanf("%d %d", &n, &m); half = max(half, n); 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]]); }

컴파일 시 표준 에러 (stderr) 메시지

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