結果

問題 No.2573 moving up
ユーザー aplysiaSheepaplysiaSheep
提出日時 2023-11-30 03:35:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 5,890 ms
コンパイル使用メモリ 325,616 KB
実行使用メモリ 7,244 KB
最終ジャッジ日時 2023-12-06 15:47:59
合計ジャッジ時間 7,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 37 ms
7,244 KB
testcase_02 AC 37 ms
7,244 KB
testcase_03 AC 11 ms
7,244 KB
testcase_04 AC 11 ms
7,244 KB
testcase_05 AC 10 ms
7,244 KB
testcase_06 AC 11 ms
7,244 KB
testcase_07 AC 9 ms
7,116 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 8 ms
6,676 KB
testcase_10 AC 9 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 10 ms
6,988 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 9 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 7 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

int main() {
    int h, w;
    cin >> h >> w;

    vector<int> x(w), y(w);
    for(int i = 0; i < w; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    mcf_graph<int, int> g(2 * w + 2);
    int s = 2 * w;
    int t = 2 * w + 1;

    for(int i = 0; i < w; i++) {
        for(int j = 0; j < w; j++) {
            if(y[i] - x[i] <= j && j <= y[i]) {
                g.add_edge(i, j + w, 1, 0);
            } else if(y[i] - x[i] > j) {
                g.add_edge(i, j + w, 1, y[i] - x[i] - j);
            } else {
                g.add_edge(i, j + w, 1, j - y[i]);
            }
        }
    }

    for(int i = 0; i < w; i++) {
        g.add_edge(s, i, 1, 0);
        g.add_edge(i + w, t, 1, 0);
    }

    int ans = g.flow(s, t, w).second;
    for(int i = 0; i < w; i++) {
        ans += x[i];
    }

    cout << ans << endl;
}
0