結果
問題 | No.2179 Planet Traveler |
ユーザー | MasKoaTS |
提出日時 | 2022-12-31 18:08:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 3,000 ms |
コード長 | 3,460 bytes |
コンパイル時間 | 4,937 ms |
コンパイル使用メモリ | 269,696 KB |
実行使用メモリ | 10,660 KB |
最終ジャッジ日時 | 2024-05-07 20:29:38 |
合計ジャッジ時間 | 5,505 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 8 ms
8,704 KB |
testcase_12 | AC | 32 ms
8,576 KB |
testcase_13 | AC | 32 ms
8,704 KB |
testcase_14 | AC | 9 ms
9,088 KB |
testcase_15 | AC | 9 ms
9,216 KB |
testcase_16 | AC | 10 ms
9,088 KB |
testcase_17 | AC | 39 ms
10,660 KB |
testcase_18 | AC | 33 ms
9,512 KB |
testcase_19 | AC | 34 ms
9,516 KB |
testcase_20 | AC | 6 ms
5,376 KB |
testcase_21 | AC | 32 ms
9,124 KB |
testcase_22 | AC | 21 ms
7,040 KB |
testcase_23 | AC | 18 ms
6,272 KB |
testcase_24 | AC | 28 ms
9,560 KB |
testcase_25 | AC | 21 ms
6,912 KB |
testcase_26 | AC | 28 ms
8,192 KB |
testcase_27 | AC | 6 ms
5,376 KB |
testcase_28 | AC | 15 ms
5,852 KB |
testcase_29 | AC | 32 ms
9,564 KB |
ソースコード
#include <math.h> #include <bits/stdc++.h> #include <atcoder/all> #pragma warning(disable: 4996) using namespace std; using namespace atcoder; #define print(n) cout << (n) << endl #define fprint(n) cout << setprecision(16) << (n) << endl #define ceil_div(a, b) (((a) - 1) / (b) + 1) #define rep(i, l, n) for (int i = (l); i < (n); i++) #define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++) #define ite(i, a) for (auto& i : a) #define last(v) v[v.size() - 1] #define all(x) x.begin(), x.end() #define lb(A, x) (lower_bound(all(A), x) - A.begin()) #define ub(A, x) (upper_bound(all(A), x) - A.begin()) #define INF 4611686018427387903ll #define inf 2147483647 #define mod 1000000007ll #define MOD 998244353ll using str = string; using ll = long long; using u32 = unsigned int; using u64 = unsigned long long; using Pair = pair<int, int>; using mint = modint1000000007; using Mint = modint998244353; template <class T> using V = vector<T>; template <class T> using VV = V<V<T> >; template <class T> using PQ = priority_queue<T, V<T>, greater<T> >; template <class T> using PQR = priority_queue<T>; template <class T> using BIT = fenwick_tree<T>; template <class T> inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; } template <class T> inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; } template <class T> inline void prints(V<T>& vec) { if (vec.size() == 0)return; cout << vec[0]; rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; } template<class T> inline vector<tuple<size_t, T> > enumerate(const vector<T>& values) { auto length = values.size(); auto values_with_indices = vector<tuple<size_t, T>>(length); for (size_t i = 0; i < length; ++i) { values_with_indices[i] = make_tuple(i, values[i]); } return values_with_indices; } inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; } inline V<int> atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; } inline V<int> Atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; } #define squ(x) ((x) * (x)) ll isqrt(ll x) { ll ok = 0; ll ng = inf; while (ng - ok > 1) { ll mid = (ok + ng) >> 1; if (squ(mid) <= x) { ok = mid; } else { ng = mid; } } return ok; } int main(void) { int n; cin >> n; V<V<ll> > p = getGrid<ll>(n, 3); V<V<ll> > dist(n, V<ll>(n, INF)); rep(i, 0, n - 1) { rep(j, i + 1, n) { if (p[i][2] == p[j][2]) { dist[i][j] = dist[j][i] = squ(p[i][0] - p[j][0]) + squ(p[i][1] - p[j][1]); } else { ll r1 = squ(p[i][0]) + squ(p[i][1]); ll r2 = squ(p[j][0]) + squ(p[j][1]); dist[i][j] = dist[j][i] = r1 + r2 - isqrt(4 * r1 * r2); // cout << i << ' ' << j << ' ' << dist[i][j] << endl; } } } V<ll> visited(n, INF); visited[0] = 0; PQ<pair<ll, int> > que = {}; que.push({ 0,0 }); while (que.empty() == false) { pair<ll, int> pa = que.top(); que.pop(); ll c_now = pa.first, v_now = pa.second; if (v_now == n - 1) { break; } if (c_now > visited[v_now]) { continue; } rep(v_next, 0, n) { ll c_next = max(c_now, dist[v_now][v_next]); // cout << v_now << ' ' << v_next << ' ' << dist[v_now][v_next] << endl; if (c_next >= visited[v_next]) { continue; } visited[v_next] = c_next; que.push({ c_next,v_next }); } } print(visited[n - 1]); return 0; }