답안 #23440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23440 2017-05-09T15:40:42 Z duongthoi1999 Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
0 ms 4488 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 3e4 + 5;
const ld eps = 1e-9;

int n, m, b[maxn], p[maxn], f[maxn];
map<int, int> d[maxn];
vector<int> a[maxn];
priority_queue<pair<int, ii>, vector<pair<int, ii> >, greater<pair<int, ii> > > pq;

int main() {
    //freopen("test.txt", "r", stdin);
    cin >> n >> m;
    rep(i, 0, m) {
        cin >> b[i] >> p[i];
        a[b[i]].pb(p[i]);
        d[b[i]][p[i]] = mod;
    }
    rep(i, 0, n) {
        sort(all(a[i]));
        a[i].resize(unique(all(a[i])) - a[i].begin());
    }
    d[b[0]][p[0]] = 0;
    pq.push(make_pair(0, ii(b[0], p[0])));
    while(!pq.empty()) {
        int du = pq.top().fi;
        int u = pq.top().se.fi;
        int t = pq.top().se.se;
        pq.pop();
        if(du != d[u][t]) continue;
        rep(i, -1, 2) if(i) {
            int v = u + i * t;
            if(v < 0 || v >= n) continue;
            if(d[v].count(t) && d[v][t] <= du + 1) continue;
            d[v][t] = du + 1;
            pq.push(make_pair(du + 1, ii(v, t)));
        }
        for (auto s : a[u]) {
            if(d[u][s] > du) {
                d[u][s] = du;
                pq.push(make_pair(du, ii(u, s)));
            }
        }
    }
    //cout << d[4][1] << endl;
    cout << d[b[1]][p[1]] << '\n';
}

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