結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Koki ShinjoKoki Shinjo
提出日時 2020-05-29 22:31:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,365 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 76,976 KB
実行使用メモリ 818,048 KB
最終ジャッジ日時 2024-04-23 23:33:21
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <limits>

int main()
{
    /* input */
    int N, M;
    int X, Y;
    int p[200000], q[200000];
    int maxp = 0, maxq = 0;
    int P[200000], Q[100000];
    scanf( " %d %d", &N, &M );
    scanf( " %d %d", &X, &Y );
    std::vector<std::vector<int>> list_lines(N);
    for ( int i=0; i<N; i++ ) {
        scanf( " %d %d", p+i, q+i );
        if ( maxp < std::abs(p[i]) ) maxp = std::abs(p[i]);
        if ( maxq < std::abs(q[i]) ) maxq = std::abs(q[i]);
    }
    for ( int i=0; i<M; i++ ) {
        scanf( " %d %d", P+i, Q+i );
        list_lines[P[i]-1].push_back(Q[i]);
        list_lines[Q[i]-1].push_back(P[i]);
    }
    std::vector<std::vector<std::vector<int>>> grid(2001,std::vector<std::vector<int>>(2001,std::vector<int>(100)));
    for ( int i=0; i<N; i++ ) {
        grid[p[i] + 1000][q[i] + 1000].push_back(i+1);
    }
    for ( int i=0; i<grid.size(); i++ ) {
        for ( int j=0; j<grid[i].size(); j++ ) {
            for ( int k=0; k<grid[i][j].size(); k++ ) {
                for ( int l=k+1; l<grid[i][j].size(); l++ ) {
                    list_lines[grid[i][j][k]-1].push_back(grid[i][j][l]);
                    list_lines[grid[i][j][l]-1].push_back(grid[i][j][k]);
                }
            }
        }
    }

    /* process */
    double cost[200000];
    double maxcost = std::numeric_limits<double>::infinity();
    for ( int i=0; i<N; i++ ) {
        cost[i] = maxcost;
    }
    std::queue<int> q_graph;
    q_graph.push(X);
    cost[X-1] = 0;
    int current, next;
    double distance;
    while ( not q_graph.empty() ) {
        current = q_graph.front();
        q_graph.pop();
        for ( int i=0; i<list_lines[current-1].size(); i++ ) {
            next = list_lines[current-1][i];
            distance = std::sqrt(
                        ( p[current-1] - p[next-1] ) * ( p[current-1] - p[next-1] )
                      + ( q[current-1] - q[next-1] ) * ( q[current-1] - q[next-1] )
                    );
            if ( cost[next-1] > cost[current-1] + distance ) {
                cost[next-1] = cost[current-1] + distance;
                q_graph.push(next);
            }
            if ( next == Y ) break;
        }

    }

    /* output */
    printf( "%.8lf\n", cost[Y-1] );

    return 0;
}
0