結果

問題 No.1479 Matrix Eraser
ユーザー jutamajutama
提出日時 2021-04-16 23:29:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 463 ms / 3,000 ms
コード長 1,692 bytes
コンパイル時間 3,851 ms
コンパイル使用メモリ 203,564 KB
実行使用メモリ 60,384 KB
最終ジャッジ日時 2023-09-16 03:08:13
合計ジャッジ時間 14,221 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 48 ms
9,704 KB
testcase_08 AC 90 ms
14,408 KB
testcase_09 AC 197 ms
26,304 KB
testcase_10 AC 362 ms
42,564 KB
testcase_11 AC 227 ms
29,732 KB
testcase_12 AC 62 ms
11,332 KB
testcase_13 AC 88 ms
14,416 KB
testcase_14 AC 66 ms
11,820 KB
testcase_15 AC 16 ms
5,520 KB
testcase_16 AC 77 ms
13,352 KB
testcase_17 AC 463 ms
50,584 KB
testcase_18 AC 456 ms
50,564 KB
testcase_19 AC 463 ms
50,584 KB
testcase_20 AC 453 ms
50,560 KB
testcase_21 AC 463 ms
50,516 KB
testcase_22 AC 457 ms
50,564 KB
testcase_23 AC 458 ms
50,584 KB
testcase_24 AC 458 ms
50,528 KB
testcase_25 AC 462 ms
50,560 KB
testcase_26 AC 450 ms
50,564 KB
testcase_27 AC 274 ms
15,448 KB
testcase_28 AC 275 ms
15,308 KB
testcase_29 AC 259 ms
15,608 KB
testcase_30 AC 276 ms
15,480 KB
testcase_31 AC 273 ms
15,592 KB
testcase_32 AC 125 ms
24,520 KB
testcase_33 AC 124 ms
24,512 KB
testcase_34 AC 126 ms
24,468 KB
testcase_35 AC 130 ms
24,476 KB
testcase_36 AC 126 ms
24,672 KB
testcase_37 AC 67 ms
24,448 KB
testcase_38 AC 230 ms
13,580 KB
testcase_39 AC 371 ms
60,384 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

void input() {
    
    
}


void solve() {
    
    
    int H, W; cin >> H >> W;
    unordered_map<int, unordered_set<int>> A;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int a; cin >> a;
            A[a].insert(i * W + j);
        }
    }
    
    int ans = 0;
    for(auto [a, as] : A) {
        if(a == 0) continue;
        
        int acc = 0, arc = 0;
        unordered_map<int, int> ac, ar;
        for(auto b : as) {
            if(ac.count(b/W) == 0) ac[b/W] = ++acc;
            if(ar.count(b%W) == 0) ar[b%W] = ++arc;
        }
        
        int Gs = acc + arc;
        atcoder::mf_graph<int> G(Gs + 2);
        for(int i = 0; i < acc; i++) {
            G.add_edge(Gs, i, 1);
        }
        for(int j = 0; j < arc; j++) {
            G.add_edge(acc + j, Gs+1, 1);
        }
        for(auto b : as) {
            G.add_edge(ac[b/W]-1, acc + ar[b%W]-1, 1);
        }
        ans += G.flow(Gs, Gs+1);
    }
    
    cout << ans << endl;
    
    
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    
    input();
    solve();
    
    return 0;
}
0