結果
問題 | No.2573 moving up |
ユーザー | 👑 AngrySadEight |
提出日時 | 2023-11-30 10:50:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,409 bytes |
コンパイル時間 | 5,996 ms |
コンパイル使用メモリ | 244,812 KB |
実行使用メモリ | 10,504 KB |
最終ジャッジ日時 | 2024-09-26 13:51:32 |
合計ジャッジ時間 | 11,315 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 373 ms
10,260 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | RE | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <atcoder/all> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define repk(i, k, n) for (int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 #define mod3 100000007 #define vi vector<int> #define vs vector<string> #define vc vector<char> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvc vector<vector<char>> #define vvl vector<vector<ll>> #define vvb vector<vector<bool>> #define vvvi vector<vector<vector<int>>> #define vvvl vector<vector<vector<ll>>> #define pii pair<int, int> #define pil pair<int, ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define vpii vector<pair<int, int>> #define vpll vector<pair<ll, ll>> #define vvpii vector<vector<pair<int, int>>> #define vvpll vector<vector<pair<ll, ll>>> using mint = modint998244353; template <typename T> void debug(T e) { cerr << e << endl; } template <typename T> void debug(vector<T> &v) { rep(i, v.size()) { cerr << v[i] << " "; } cerr << endl; } template <typename T> void debug(vector<vector<T>> &v) { rep(i, v.size()) { rep(j, v[i].size()) { cerr << v[i][j] << " "; } cerr << endl; } } template <typename T> void debug(vector<pair<T, T>> &v) { rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; } } template <typename T> void debug(set<T> &st) { for (auto itr = st.begin(); itr != st.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template <typename T> void debug(multiset<T> &ms) { for (auto itr = ms.begin(); itr != ms.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template <typename T> void debug(map<T, T> &mp) { for (auto itr = mp.begin(); itr != mp.end(); itr++) { cerr << itr->first << " " << itr->second << endl; } } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << H << " "; debug_out(T...); } ll INF = 1000000000; int main() { ll H, W; cin >> H >> W; vector<ll> a(W); vector<ll> b(W); for (ll i = 0; i < W; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } queue<pll> que; vector<vector<ll>> dists(W, vector<ll>(W)); vector<vector<ll>> dist(H, vector<ll>(H + W, INF)); vector<ll> dx = {-1, -1, 0, 0, 1, 1}; vector<ll> dy = {-1, 0, -1, 1, 0, 1}; for (ll i = 0; i < W; i++) { for (ll j = 0; j < H; j++) { for (ll k = 0; k < H + W; k++) { dist[j][k] = INF; } } dist[a[i]][b[i]] = 0; que.push(pll(a[i], b[i])); while (que.size()) { pll p = que.front(); que.pop(); ll px = p.first; ll py = p.second; for (ll j = 0; j < 6; j++) { if (px + dx[j] >= 0 && px + dx[j] < H && py + dy[j] >= 0 && py + dy[j] < W + px + dx[j]) { if (dist[px + dx[j]][py + dy[j]] < INF) { continue; } dist[px + dx[j]][py + dy[j]] = dist[px][py] + 1; que.push(pll(px + dx[j], py + dy[j])); } } } // debug(dist); for (ll j = 0; j < W; j++) { dists[i][j] = dist[0][j]; } } mcf_graph<ll, ll> graph(2 * W + 2); for (ll i = 0; i < W; i++) { for (ll j = 0; j < W; j++) { graph.add_edge(i, W + j, 1, INF - dist[i][j]); } } for (ll i = 0; i < W; i++) { graph.add_edge(2 * W, i, 1, 0); } for (ll i = 0; i < W; i++) { graph.add_edge(W + i, 2 * W + 1, 1, 0); } ll ans = INF * W; pll flp = graph.flow(2 * W, 2 * W + 1); cout << ans - flp.second << endl; }