結果

問題 No.2573 moving up
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-12-02 15:33:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 4,720 ms
コンパイル使用メモリ 278,936 KB
実行使用メモリ 7,268 KB
最終ジャッジ日時 2023-12-06 15:48:27
合計ジャッジ時間 6,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 70 ms
7,268 KB
testcase_02 AC 83 ms
7,268 KB
testcase_03 AC 32 ms
7,268 KB
testcase_04 AC 31 ms
7,268 KB
testcase_05 AC 33 ms
7,268 KB
testcase_06 AC 31 ms
7,268 KB
testcase_07 AC 30 ms
7,140 KB
testcase_08 AC 3 ms
6,548 KB
testcase_09 AC 14 ms
6,548 KB
testcase_10 AC 26 ms
6,564 KB
testcase_11 AC 6 ms
6,548 KB
testcase_12 AC 15 ms
6,548 KB
testcase_13 AC 28 ms
7,012 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 10 ms
6,548 KB
testcase_18 AC 10 ms
6,548 KB
testcase_19 AC 23 ms
6,548 KB
testcase_20 AC 4 ms
6,548 KB
testcase_21 AC 3 ms
6,548 KB
testcase_22 AC 7 ms
6,548 KB
testcase_23 AC 4 ms
6,548 KB
testcase_24 AC 9 ms
6,548 KB
testcase_25 AC 17 ms
6,548 KB
testcase_26 AC 4 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream& operator<<(ostream& os, const mint P) { return os << P.val(); };

void solve() {
  int h, w;
  cin >> h >> w;
  vi x(w), y(w);
  rep(i, 0, w) cin >> x[i] >> y[i];

  int s = w * 2;
  mcf_graph<int, int> g(s + 2);
  rep(i, 0, w) g.add_edge(s, i, 1, 0);
  rep(i, 0, w) g.add_edge(w + i, s + 1, 1, 0);

  rep(i, 0, w) rep(j, 0, w) {
    int dx = x[i] - 1, dy = y[i] - (j + 1);
    if (dx < 0) dx = -dx, dy = -dy;
    int c = 0;
    while (dx > 0 && dy > 0) c++, dx--, dy--;
    dy = abs(dy);
    while (dx) c++, dx--;
    while (dy) c++, dy--;
    g.add_edge(i, j + w, 1, c);
  }

  cout << g.flow(s, s + 1).second << "\n";
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0