結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | Koki Shinjo |
提出日時 | 2020-05-29 22:29:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,343 bytes |
コンパイル時間 | 981 ms |
コンパイル使用メモリ | 76,268 KB |
実行使用メモリ | 110,284 KB |
最終ジャッジ日時 | 2024-11-06 05:50:15 |
合計ジャッジ時間 | 17,909 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
98,900 KB |
testcase_01 | AC | 98 ms
99,024 KB |
testcase_02 | AC | 204 ms
108,216 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 | 118 ms
100,312 KB |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 146 ms
101,928 KB |
testcase_19 | RE | - |
testcase_20 | WA | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | AC | 102 ms
99,024 KB |
testcase_24 | AC | 102 ms
98,900 KB |
testcase_25 | AC | 120 ms
100,184 KB |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 114 ms
100,112 KB |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 164 ms
105,212 KB |
testcase_33 | RE | - |
testcase_34 | AC | 147 ms
102,620 KB |
testcase_35 | RE | - |
testcase_36 | AC | 103 ms
99,032 KB |
testcase_37 | AC | 103 ms
99,312 KB |
testcase_38 | AC | 102 ms
99,040 KB |
testcase_39 | AC | 106 ms
99,444 KB |
testcase_40 | AC | 101 ms
99,028 KB |
testcase_41 | RE | - |
testcase_42 | WA | - |
testcase_43 | RE | - |
testcase_44 | AC | 137 ms
104,228 KB |
testcase_45 | RE | - |
testcase_46 | AC | 102 ms
99,020 KB |
testcase_47 | AC | 100 ms
99,028 KB |
ソースコード
#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; }