답안 #232564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232564 2020-05-17T10:58:15 Z balbit Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
5 ms 640 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()

#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#endif // BALBIT

#define pii pair<int, int>
#define f first
#define s second

#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define pb push_back

const int maxn = 2005;
vector<pii> g[maxn];
int d[maxn];
set<pii> bp;
set<int> hv[maxn];
signed main(){
    IOS();
    int n,m; cin>>n>>m;
    int S = -1, T = -1;
    for (int i = 0; i<m; ++i) {
        int b,p; cin>>b>>p;
        if (bp.count({b,p})) continue;
            bp.insert({b,p});
        if (i == 0) S = b;
        if (i == 1) T = b;
        hv[b].insert(p);
    }
    for(int b = 0; b<m; ++b){
        for (int p : hv[b]) {
            for (int df = 1; b + df * p < n; ++df ) {
                if (hv[b+df*p].count(p)) break;
                g[b].pb({b+df*p, abs(df)});
            }
            for (int df = -1; b + df * p >=0; --df ) {
                if (hv[b+df*p].count(p)) break;
                g[b].pb({b+df*p, abs(df)});
            }
        }
    }
    memset(d, 0x3f, sizeof d);
    d[S] = 0;
    priority_queue<pii, vector<pii>, greater<pii> > pq;
    pq.push({0,S});
    while (!pq.empty()) {
        int v = pq.top().s; int w = pq.top().f; pq.pop();
        bug(v, d[v]);
        if (d[v] != w) {
            continue;
        }
        for (pii u : g[v]) {
            if (d[u.f] > d[v] + u.s) {
                d[u.f] = d[v] + u.s;
                pq.push({d[u.f], u.f});
            }
        }
    }
    if (d[T] != 0x3f3f3f3f)
        cout<<d[T]<<endl;
    else cout<<-1<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -