結果
問題 | No.2321 Continuous Flip |
ユーザー | rogi52 |
提出日時 | 2023-05-27 03:59:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 350 ms / 2,000 ms |
コード長 | 6,911 bytes |
コンパイル時間 | 2,494 ms |
コンパイル使用メモリ | 216,416 KB |
実行使用メモリ | 43,492 KB |
最終ジャッジ日時 | 2024-06-07 11:43:27 |
合計ジャッジ時間 | 13,684 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 312 ms
37,780 KB |
testcase_05 | AC | 318 ms
37,744 KB |
testcase_06 | AC | 318 ms
37,832 KB |
testcase_07 | AC | 312 ms
37,800 KB |
testcase_08 | AC | 334 ms
37,840 KB |
testcase_09 | AC | 325 ms
37,700 KB |
testcase_10 | AC | 314 ms
37,844 KB |
testcase_11 | AC | 314 ms
37,684 KB |
testcase_12 | AC | 336 ms
37,836 KB |
testcase_13 | AC | 325 ms
37,772 KB |
testcase_14 | AC | 315 ms
37,684 KB |
testcase_15 | AC | 328 ms
37,712 KB |
testcase_16 | AC | 313 ms
37,852 KB |
testcase_17 | AC | 324 ms
37,844 KB |
testcase_18 | AC | 323 ms
37,664 KB |
testcase_19 | AC | 339 ms
37,748 KB |
testcase_20 | AC | 313 ms
37,856 KB |
testcase_21 | AC | 313 ms
37,840 KB |
testcase_22 | AC | 335 ms
37,708 KB |
testcase_23 | AC | 350 ms
37,776 KB |
testcase_24 | AC | 107 ms
29,824 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 100 ms
29,832 KB |
testcase_27 | AC | 105 ms
32,384 KB |
testcase_28 | AC | 224 ms
43,476 KB |
testcase_29 | AC | 225 ms
43,368 KB |
testcase_30 | AC | 235 ms
43,492 KB |
testcase_31 | AC | 221 ms
43,484 KB |
testcase_32 | AC | 237 ms
43,488 KB |
testcase_33 | AC | 246 ms
43,360 KB |
ソースコード
#line 2 "src/cp-template.hpp" #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using i128 = __int128_t; template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; } template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; } #line 2 "src/utility/rep_itr.hpp" template < class T > struct itr { T i, d; constexpr itr(const T i) noexcept : i(i), d(1) {} constexpr itr(const T i, const T d) noexcept : i(i), d(d) {} void operator++() noexcept { i += d; } constexpr int operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return d > 0 ? i < x.i : i > x.i; } }; template < class T > struct rep { const itr< T > s, t; constexpr rep(const T t) noexcept : s(0), t(t) {} constexpr rep(const T s, const T t) noexcept : s(s), t(t) {} constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {} constexpr auto begin() const noexcept { return s; } constexpr auto end() const noexcept { return t; } }; template < class T > struct revrep { const itr < T > s, t; constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {} constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {} constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {} constexpr auto begin() const noexcept { return s; } constexpr auto end() const noexcept { return t; } }; #line 2 "src/utility/io.hpp" namespace scanner { struct sca { template < class T > operator T() { T s; cin >> s; return s; } }; struct vec { int n; vec(int n) : n(n) {} template < class T > operator vector< T >() { vector< T > v(n); for(T& x : v) cin >> x; return v; } }; struct mat { int h,w; mat(int h, int w) : h(h), w(w) {} template < class T > operator vector< vector< T > >() { vector m(h, vector< T >(w)); for(vector< T >& v : m) for(T& x : v) cin >> x; return m; } }; struct speedup { speedup() { cin.tie(0); ios::sync_with_stdio(0); } } su; } scanner::sca in() { return scanner::sca(); } scanner::vec in(int n) { return scanner::vec(n); } scanner::mat in(int h, int w) { return scanner::mat(h, w); } namespace printer { void precision(int d) { cout << fixed << setprecision(d); } void flush() { cout.flush(); } } int print() { cout << '\n'; return 0; } template < class head, class... tail > int print(head&& h, tail&&... t) { cout << h; if(sizeof...(tail)) cout << ' '; return print(forward<tail>(t)...); } template < class T > int print(vector< T > a, char sep = ' ') { int n = a.size(); for(int i : rep(n)) cout << a[i] << (i != n - 1 ? sep : '\n'); return 0; } template < class T > int print(vector< vector< T > > a) { if(a.empty()) return 0; int h = a.size(), w = a[0].size(); for(int i : rep(h)) for(int j : rep(w)) cout << a[i][j] << (j != w - 1 ? ' ' : '\n'); return 0; } #line 2 "src/utility/key_val.hpp" template < class K, class V > struct key_val { K key; V val; key_val() {} key_val(K key, V val) : key(key), val(val) {} }; #line 2 "src/utility/vec_op.hpp" template < class T > key_val< int, T > max_of(const vector< T >& a) { int i = max_element(a.begin(), a.end()) - a.begin(); return {i, a[i]}; } template < class T > key_val< int, T > min_of(const vector< T >& a) { int i = min_element(a.begin(), a.end()) - a.begin(); return {i, a[i]}; } template < class T > T sum_of(const vector< T >& a) { T sum = 0; for(const T x : a) sum += x; return sum; } template < class T > vector<int> freq_of(const vector< T >& a, T L, T R) { vector<int> res(R - L); for(const T x : a) res[x - L]++; return res; } template < class T > vector<int> freq_of(const vector< T >& a, T R) { return freq_of(a, T(0), R); } template < class T > struct prefix_sum { vector< T > s; prefix_sum(const vector< T >& a) : s(a) { s.insert(s.begin(), T(0)); for(int i : rep(a.size())) s[i + 1] += s[i]; } // [L, R) T sum(int L, int R) { return s[R] - s[L]; } }; #line 1 "src/graph/shortest_path.hpp" // g <- pair < v , cost > template < class T > vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) { T INF = numeric_limits< T >::max(); vector<T> dist(graph.size(), INF); priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q; q.push({dist[s] = T(0), s}); while(!q.empty()){ auto [uc, ui] = q.top(); q.pop(); if(uc != dist[ui]) continue; for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) q.push({dist[vi] = uc + vc, vi}); } return dist; } // g <- pair < v , cost > template < class T > vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, vector<int> &starts) { T INF = numeric_limits< T >::max(); vector<T> dist(graph.size(), INF); priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q; for(int s : starts) q.push({dist[s] = T(0), s}); while(!q.empty()){ auto [uc, ui] = q.top(); q.pop(); if(uc != dist[ui]) continue; for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) q.push({dist[vi] = uc + vc, vi}); } return dist; } // g <- pair < v , cost > template < class T > pair< T, vector<int> > shortest_path(vector<vector<pair<int, T>>> &graph, int s, int t) { T INF = numeric_limits< T >::max(); vector<T> dist(graph.size(), INF); vector<int> prev(graph.size(), -1); priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q; q.push({dist[s] = T(0), s}); while(!q.empty()){ auto [uc, ui] = q.top(); q.pop(); if(uc != dist[ui]) continue; for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) q.push({dist[vi] = uc + vc, vi}), prev[vi] = ui; } vector<int> path; if(dist[t] != INF) { for(int v = t; v != -1; v = prev[v]) path.push_back(v); reverse(path.begin(), path.end()); } return {dist[t], path}; } #line 3 "A.cpp" int main() { ll N = in(), M = in(), C = in(); vector<ll> A = in(N), L(M), R(M); for(int i : rep(M)) { L[i] = in(); L[i]--; R[i] = in(); } vector<vector<pair<int,ll>>> G(N + 1); for(int i : rep(N)) { G[i + 1].push_back({i, A[i]}); G[i].push_back({i + 1, A[i]}); } for(int i : rep(M)) { G[L[i]].push_back({R[i], C}); G[R[i]].push_back({L[i], C}); } print(sum_of(A) - dijkstra(G, 0)[N]); }