結果

問題 No.2695 Warp Zone
コンテスト
ユーザー toppo57
提出日時 2026-11-02 10:34:32
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 19 ms / 2,000 ms
+ 620µs
コード長 1,386 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,258 ms
コンパイル使用メモリ 176,916 KB
実行使用メモリ 35,124 KB
最終ジャッジ日時 2026-11-02 10:34:39
合計ジャッジ時間 5,571 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <utility>
using namespace std;
using ll = long long;

struct point{
    ll x, y;

    ll distance(point q){
        return abs(x-q.x)+abs(y-q.y);
    }
};

const ll INF = 1LL<<60;

int N;

point pos[2010];
ll G[2010][2010];
ll D[2010];
bool visited[2010];

void Dijkstra(int src){
    fill(&D[0], &D[0]+2010, INF);
    fill(&visited[0], &visited[0] + 2010, false);
    D[src]=0LL;

    for (int i=0;i<2*N+2;i++) {
        int u = -1;
        ll min_dist = INF;
        for (int j=0;j<2*N+2;j++) {
            if (!visited[j] && D[j] < min_dist) {
                min_dist = D[j];
                u = j;
            }
        }
        if (u == -1) break;

        visited[u] = true;

        for (int v=0;v<2*N+2;v++) {
            if (!visited[v] && D[u]+G[u][v]<D[v]) {
                D[v] = D[u]+G[u][v];
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll H, W;
    cin>>H>>W>>N;
    pos[0]={1LL, 1LL}, pos[1]={H, W};
    for (int i=1;i<=N;i++){
        cin>>pos[2*i].x>>pos[2*i].y>>pos[2*i+1].x>>pos[2*i+1].y;
    }
    for (int i=0;i<2*N+2;i++){
        for (int j=i;j<2*N+2;j++){
            G[i][j]=pos[i].distance(pos[j]);
            G[j][i]=G[i][j];
        }
    }
    for (int i=1;i<=N;i++) G[2*i][2*i+1]=1;

    Dijkstra(0);
    cout << D[1] << "\n";

    return 0;
}
0