제출 #25691

#제출 시각아이디문제언어결과실행 시간메모리
25691gabrielsimoesJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
0 ms1852 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,pii> plii; const int MAXN = 3e4+10; const int BLK = 2000; #define dist first #define index second.first #define delta second.second int N, M, X, Y; vector<pii> v[MAXN]; ll d[MAXN][BLK]; map<pii, bool> ok; priority_queue<plii, vector<plii>, greater<plii>> q; ll dBig[MAXN]; int posBig[MAXN]; inline void proc(int i, int dx, ll dd) { if (dx < BLK) { if (d[i][dx] == -1 || dd < d[i][dx]) { d[i][dx] = dd; q.push({dd, {i, dx}}); } } else { if (dBig[i] == -1 || dd < dBig[i]) { dBig[i] = dd; q.push({dd, {i, dx}}); } } } inline void procBig(int cur, int dx, ll d0) { // int cnt = cur/dx; // int i = cur - cnt*dx; // while (i < N) { // if (i != cur) proc(i, 0, d0 + abs(cnt)); // i += dx; cnt--; // } int i = cur, cnt = 0; while ((i-=dx) >= 0) proc(i, 0, d0 + (++cnt)); i = cur, cnt = 0; while ((i+=dx) < N) proc(i, 0, d0 + (++cnt)); } inline void procSmall(int cur, int dx, ll d0) { // procBig(cur, dx, d0); // return; if (cur - dx >= 0) { proc(cur-dx, dx, d0+1); proc(cur-dx, 0, d0+1); } if (cur + dx < N) { proc(cur+dx, dx, d0+1); proc(cur+dx, 0, d0+1); } } inline void proc0(int ix) { for (pii p : v[ix]) proc(p.first<BLK?ix:p.second, p.first, d[ix][0]); } void dijkstra() { memset(d, -1, sizeof(d)); d[X][0] = 0; q.push({0,{X,0}}); while (!q.empty()) { plii p = q.top(); q.pop(); if (p.delta < BLK && d[p.index][p.delta] < p.dist) continue; if (p.delta >= BLK && dBig[p.index] < p.dist) continue; if (p.delta == 0) proc0(p.index); else if (p.delta < BLK) procSmall(p.index, p.delta, p.dist); else procBig(posBig[p.index], p.delta, p.dist); } } int main() { scanf("%d %d", &N, &M); for (int i = 0,a,b; i < M; i++) { scanf("%d %d", &a, &b); if (i == 0) X = a; else if (i == 1) Y = a; if (b != 0) v[a].push_back(pii(b,i)); posBig[i] = a; } for (int i = 0; i < N; i++) sort(v[i].begin(), v[i].end()), v[i].resize(unique(v[i].begin(), v[i].end()) - v[i].begin()); dijkstra(); printf("%lld\n", d[Y][0]); }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:87:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
skyscraper.cpp:89:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
                         ^
#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...