結果

問題 No.1479 Matrix Eraser
ユーザー SSRSSSRS
提出日時 2021-04-16 20:21:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 3,000 ms
コード長 1,474 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 192,076 KB
実行使用メモリ 31,696 KB
最終ジャッジ日時 2023-09-15 20:57:21
合計ジャッジ時間 13,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 51 ms
6,588 KB
testcase_08 AC 97 ms
8,836 KB
testcase_09 AC 226 ms
14,736 KB
testcase_10 AC 442 ms
22,688 KB
testcase_11 AC 260 ms
16,204 KB
testcase_12 AC 67 ms
7,468 KB
testcase_13 AC 94 ms
8,916 KB
testcase_14 AC 70 ms
7,640 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 82 ms
8,180 KB
testcase_17 AC 543 ms
26,136 KB
testcase_18 AC 548 ms
25,968 KB
testcase_19 AC 544 ms
26,128 KB
testcase_20 AC 548 ms
26,128 KB
testcase_21 AC 554 ms
26,036 KB
testcase_22 AC 564 ms
25,996 KB
testcase_23 AC 559 ms
25,984 KB
testcase_24 AC 558 ms
25,992 KB
testcase_25 AC 565 ms
26,020 KB
testcase_26 AC 558 ms
26,028 KB
testcase_27 AC 155 ms
7,428 KB
testcase_28 AC 154 ms
7,040 KB
testcase_29 AC 156 ms
7,348 KB
testcase_30 AC 155 ms
7,232 KB
testcase_31 AC 157 ms
7,288 KB
testcase_32 AC 89 ms
14,376 KB
testcase_33 AC 90 ms
14,400 KB
testcase_34 AC 89 ms
14,332 KB
testcase_35 AC 89 ms
14,476 KB
testcase_36 AC 89 ms
14,484 KB
testcase_37 AC 36 ms
4,376 KB
testcase_38 AC 171 ms
6,528 KB
testcase_39 AC 415 ms
31,696 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/maxflow>
using namespace std;
using namespace atcoder;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  map<int, vector<pair<int, int>>> mp;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (A[i][j] > 0){
        mp[A[i][j]].push_back(make_pair(i, j));
      }
    }
  }
  int ans = 0;
  for (auto P : mp){
    int cnt = P.second.size();
    vector<int> X, Y;
    for (int i = 0; i < cnt; i++){
      X.push_back(P.second[i].first);
      Y.push_back(P.second[i].second);
    }
    sort(X.begin(), X.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    sort(Y.begin(), Y.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    int Xcnt = X.size(), Ycnt = Y.size();
    vector<int> x(cnt), y(cnt);
    for (int i = 0; i < cnt; i++){
      x[i] = lower_bound(X.begin(), X.end(), P.second[i].first) - X.begin();
      y[i] = lower_bound(Y.begin(), Y.end(), P.second[i].second) - Y.begin();
    }
    mf_graph<int> G(Xcnt + Ycnt + 2);
    for (int i = 0; i < Xcnt; i++){
      G.add_edge(Xcnt + Ycnt, i, 1);
    }
    for (int i = 0; i < Ycnt; i++){
      G.add_edge(Xcnt + i, Xcnt + Ycnt + 1, 1);
    }
    for (int i = 0; i < cnt; i++){
      G.add_edge(x[i], Xcnt + y[i], 1);
    }
    ans += G.flow(Xcnt + Ycnt, Xcnt + Ycnt + 1);
  }
  cout << ans << endl;
}
0