結果
問題 |
No.168 ものさし
|
ユーザー |
|
提出日時 | 2015-06-30 11:07:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 882 ms |
コンパイル使用メモリ | 80,652 KB |
実行使用メモリ | 27,284 KB |
最終ジャッジ日時 | 2024-12-24 07:09:52 |
合計ジャッジ時間 | 2,081 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <cmath> #include <queue> using namespace std; typedef pair<long long, long long> PLL; int main() { int n, x, y; vector<PLL> points; cin >> n; points.assign(n, PLL()); for (int i = 0; i < n; i++) { cin >> x >> y; points[i] = make_pair(x, y); } vector< vector<PLL> > length2(n, vector<PLL>(n, PLL())); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long long x = points[i].first - points[j].first; long long y = points[i].second - points[j].second; length2[i][j] = make_pair(x * x + y * y, i * 10000 + j); } } vector<bool> reach(n, false); priority_queue<PLL, vector<PLL>, greater<PLL> > que; for (int i = 1; i < n; i++) { que.push(length2[0][i]); } reach[0] = true; long long ans2 = -1; while (!que.empty()) { auto val = que.top(); que.pop(); ans2 = max(ans2, val.first); int to = val.second % 10000; if (to == n - 1) { break; } else if (reach[to]) { continue; } reach[to] = true; for (int i = 0; i < n; i++) { if (!reach[i]) { que.push(length2[to][i]); } } } long long ans = sqrt(ans2); while(ans * ans < ans2) { ans++; } ans = (ans + 9) / 10 * 10; cout << ans << endl; return 0; }