結果

問題 No.2695 Warp Zone
ユーザー shinchanshinchan
提出日時 2024-03-22 22:25:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 210,920 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-22 22:25:52
合計ジャッジ時間 3,370 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 12 ms
6,548 KB
testcase_04 AC 12 ms
6,548 KB
testcase_05 AC 12 ms
6,548 KB
testcase_06 AC 12 ms
6,548 KB
testcase_07 AC 12 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 6 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 7 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 8 ms
6,548 KB
testcase_15 AC 5 ms
6,548 KB
testcase_16 AC 3 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 10 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 9 ms
6,548 KB
testcase_21 AC 8 ms
6,548 KB
testcase_22 AC 5 ms
6,548 KB
testcase_23 AC 7 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    vector<pair<ll, ll>> v(n * 2 + 2);
    vector<ll> dis(n * 2 + 2, INF);
    dis[n * 2] = 0;
    v[n * 2] = {1, 1};
    v[n * 2 + 1] = {h, w};
    rep(i, n) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        v[i * 2] = {a, b};
        v[i * 2 + 1] = {c, d};
    }
    // now % 2 == 0 and now < n * 2 -> now + 1 : dis + 1
    using P = pair<ll, ll>;
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push({0, n * 2});
    while(!Q.empty()){
        P p = Q.top();
        Q.pop();
        ll cur = p.second;
        if(dis[cur] < p.first) continue;
        rep(i, n * 2 + 2) {
            if(dis[i] > abs(v[cur].first - v[i].first) + abs(v[cur].second - v[i].second) + dis[cur]) {
                dis[i] = abs(v[cur].first - v[i].first) + abs(v[cur].second - v[i].second) + dis[cur];
                Q.push({dis[i], i});
            }
        }
        if(cur % 2 == 0 and cur < n * 2) {
            if(dis[cur + 1] > dis[cur] + 1) {
                dis[cur + 1] = dis[cur] + 1;
                Q.push({dis[cur + 1], cur + 1});
            }
        }
    }
    cout << dis.back() << endl;
    return 0;
}
0