# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72726 | 2018-08-26T21:06:43 Z | Pajaraja | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 4 ms | 2640 KB |
#include <bits/stdc++.h> #define MAXN 30007 using namespace std; vector<int> g[MAXN],w[MAXN],v[MAXN],c; bool vi[MAXN]; int dist[MAXN]; void dijkstra(int s) { priority_queue<pair<int,int> > pq; pq.push(make_pair(0,s)); while(!pq.empty()) { int u=pq.top().second,d=-pq.top().first; pq.pop(); if(vi[u]) continue; dist[u]=d; vi[u]=true; for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) pq.push(make_pair(-d-w[u][i],g[u][i])); } } bool binarna(int l,int r,int k,int val) { if(r<l) return false; int s=(l+r)/2; if(v[k][s]==val) return true; if(val<v[k][s]) return binarna(l,s-1,k,val); return binarna(s+1,r,k,val); } int main() { int n,m,st,en,t1,t2; scanf("%d%d",&n,&m); scanf("%d%d%d%d",&st,&t1,&en,&t2); v[st].push_back(t1); v[en].push_back(t2); for(int i=0;i<m-2;i++) { scanf("%d%d",&t1,&t2); v[t1].push_back(t2); } for(int i=0;i<n;i++) sort(v[i].begin(),v[i].end()); for(int i=0;i<n;i++) { for(int j=v[i].size()-1;j>=0;j--) { int t=v[i][j],cur=i+t,cnt=0; while(cur<n && v[cur].size()>0) { cnt++; if(!vi[cur]) { g[i].push_back(cur); w[i].push_back(cnt); vi[cur]=true; c.push_back(cur); } if(binarna(0,v[cur].size()-1,cur,t)) break; cur+=t; } cur=i-t; cnt=0; while(cur>=0) { cnt++; if(!vi[cur] && v[cur].size()>0) { g[i].push_back(cur); w[i].push_back(cnt); vi[cur]=true; c.push_back(cur); } if(binarna(0,v[cur].size()-1,cur,t)) break; cur-=t; } } for(int j=0;j<c.size();j++) vi[c[j]]=false; c.clear(); } dijkstra(st); if(!vi[en]) dist[en]=-1; printf("%d",dist[en]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2424 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2536 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2536 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |