結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
97,408 KB
testcase_01 AC 94 ms
97,408 KB
testcase_02 AC 181 ms
108,032 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 111 ms
99,072 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 137 ms
100,992 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 95 ms
97,408 KB
testcase_24 AC 97 ms
97,536 KB
testcase_25 AC 111 ms
98,944 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 111 ms
98,816 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 154 ms
104,320 KB
testcase_33 RE -
testcase_34 AC 139 ms
101,504 KB
testcase_35 RE -
testcase_36 AC 99 ms
97,536 KB
testcase_37 AC 97 ms
97,920 KB
testcase_38 AC 95 ms
97,408 KB
testcase_39 AC 96 ms
97,920 KB
testcase_40 AC 96 ms
97,536 KB
testcase_41 RE -
testcase_42 WA -
testcase_43 RE -
testcase_44 AC 130 ms
101,504 KB
testcase_45 RE -
testcase_46 AC 95 ms
97,536 KB
testcase_47 AC 94 ms
97,536 KB
権限があれば一括ダウンロードができます

ソースコード

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));
    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