제출 #725325

#제출 시각아이디문제언어결과실행 시간메모리
725325quiet_spaceJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
430 ms112456 KiB
#include <queue> #include <cstdio> #include <cctype> #include <vector> #include <bitset> #include <algorithm> using namespace std; #define FOR(i,j,k) for(int i=j; i<=k; ++i) #define ROF(i,j,k) for(int i=j; i>=k; --i) inline int read (void) { int x = 0, f = 1, ch = getchar(); while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); } while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int maxn = 30005; struct Node { int pos, fot, dis; }; bitset <maxn> b[maxn]; vector <int> v[maxn]; queue <Node> q; int d[maxn]; int main (void) { int n = read(), m = read(), p0 = -1, p1 = -1; FOR(i,1,m) { int x = read(), y = read(); if(p0 == -1) p0 = x; else if(p1 == -1) p1 = x; v[x].push_back(y); } d[p0] = 1; for(auto&it:v[p0]) if(!b[p0].test(it)) { b[p0].set(it); q.push((Node) {p0, it, 1}); } while(!d[p1] && !q.empty()) { Node cur = q.front(); q.pop(); int x = cur.pos, y = cur.fot, z = cur.dis; if(x - y >= 0 && !b[x-y].test(y)) { b[x-y].set(y); q.push((Node) {x-y, y, z+1}); if(!d[x-y]) { d[x-y] = z+1; for(auto&it:v[x-y]) if(!b[x-y].test(it)) { b[x-y].set(it); q.push((Node) {x-y, it, z+1}); } } } if(x + y < n && !b[x+y].test(y)) { b[x+y].set(y); q.push((Node) {x+y, y, z+1}); if(!d[x+y]) { d[x+y] = z+1; for(auto&it:v[x+y]) if(!b[x+y].test(it)) { b[x+y].set(it); q.push((Node) {x+y, it, z+1}); } } } } printf("%d\n", d[p1]-1); return 0; }
#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...