답안 #240990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240990 2020-06-22T02:11:31 Z WhaleVomit Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
7 ms 2560 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

template<int SZ> struct dijkstra {
    const int inf = 1e8;
    vector<pi> adj[SZ];
    int d[SZ];

    void addEdge(int u, int v, int l) {
        adj[u].pb(mp(v, l));
    }
    int dist(int v) {
        return d[v];
    }
    void build(int u) {
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
        M00(i, SZ) d[i] = inf;
        pq.push(mp(0, u));
        while(!pq.empty()) {
            pi t = pq.top(); pq.pop();
            if(d[t.s] != inf) continue;
            d[t.s] = t.f;

            for(auto v: adj[t.s]) {
                if(d[v.f] > d[t.s] + v.s) {
                    pq.push(mp(d[t.s]+v.s, v.f));
                }
            }
        }
    }
};

const int MAX_N = 30030;
int n, m;
set<int> doges[MAX_N];
dijkstra<MAX_N> dj;

int main() { FAST
    cin >> n >> m;
    int st = -1, en = -1;
    M00(i, m) {
        int b, p; cin >> b >> p;
        if(i == 0) st = b;
        else if(i == 1) en = b;
        doges[b].insert(p);
    }
    M00(i, n) {
        for(int j: doges[i]) {
            for(int x = i+j; x < n; x += j) {
                dj.addEdge(i,x,(x-i)/j);
                if(doges[x].count(j)) break;
            }
            for(int x = i-j; x >= 0; x -= j) {
                dj.addEdge(i,x,(i-x)/j);
                if(doges[x].count(j)) break;
            }
        }
    }
    dj.build(st);
    cout << dj.dist(en) << "\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 7 ms 2560 KB Output is correct
4 Incorrect 6 ms 2560 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Incorrect 6 ms 2560 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Incorrect 6 ms 2560 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 7 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Incorrect 7 ms 2560 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Incorrect 6 ms 2560 KB Output isn't correct
5 Halted 0 ms 0 KB -