結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | Koki Shinjo |
提出日時 | 2020-05-29 22:25:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,388 bytes |
コンパイル時間 | 1,068 ms |
コンパイル使用メモリ | 75,628 KB |
実行使用メモリ | 111,692 KB |
最終ジャッジ日時 | 2024-11-06 05:43:17 |
合計ジャッジ時間 | 19,630 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 99 ms
99,020 KB |
testcase_01 | AC | 100 ms
99,024 KB |
testcase_02 | WA | - |
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,252 KB |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 146 ms
101,764 KB |
testcase_19 | RE | - |
testcase_20 | WA | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | AC | 102 ms
99,028 KB |
testcase_24 | AC | 101 ms
99,028 KB |
testcase_25 | AC | 117 ms
100,060 KB |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 117 ms
100,112 KB |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 167 ms
105,260 KB |
testcase_33 | RE | - |
testcase_34 | AC | 149 ms
102,512 KB |
testcase_35 | RE | - |
testcase_36 | AC | 103 ms
99,028 KB |
testcase_37 | AC | 103 ms
99,316 KB |
testcase_38 | AC | 101 ms
99,036 KB |
testcase_39 | AC | 102 ms
99,184 KB |
testcase_40 | AC | 104 ms
99,024 KB |
testcase_41 | RE | - |
testcase_42 | WA | - |
testcase_43 | RE | - |
testcase_44 | WA | - |
testcase_45 | RE | - |
testcase_46 | AC | 100 ms
99,024 KB |
testcase_47 | AC | 102 ms
99,024 KB |
ソースコード
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <queue> 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++ ) { if ( grid[i][j].size() > 0 ) { 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 = ( maxp + maxq ) * 2.0; 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; }