結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 49 ms
9,796 KB
testcase_08 AC 91 ms
14,460 KB
testcase_09 AC 198 ms
25,968 KB
testcase_10 AC 365 ms
42,568 KB
testcase_11 AC 231 ms
29,484 KB
testcase_12 AC 62 ms
11,320 KB
testcase_13 AC 89 ms
14,340 KB
testcase_14 AC 66 ms
11,960 KB
testcase_15 AC 16 ms
5,308 KB
testcase_16 AC 85 ms
13,384 KB
testcase_17 AC 487 ms
50,516 KB
testcase_18 AC 462 ms
50,544 KB
testcase_19 AC 462 ms
50,560 KB
testcase_20 AC 462 ms
50,644 KB
testcase_21 AC 462 ms
50,600 KB
testcase_22 AC 458 ms
50,448 KB
testcase_23 AC 465 ms
50,612 KB
testcase_24 AC 462 ms
50,656 KB
testcase_25 AC 462 ms
50,420 KB
testcase_26 AC 460 ms
50,524 KB
testcase_27 AC 287 ms
15,428 KB
testcase_28 AC 287 ms
15,172 KB
testcase_29 AC 301 ms
15,532 KB
testcase_30 AC 294 ms
15,456 KB
testcase_31 AC 291 ms
15,596 KB
testcase_32 AC 135 ms
24,368 KB
testcase_33 AC 132 ms
24,504 KB
testcase_34 AC 135 ms
24,400 KB
testcase_35 AC 135 ms
24,496 KB
testcase_36 AC 133 ms
24,544 KB
testcase_37 AC 68 ms
24,528 KB
testcase_38 AC 239 ms
13,580 KB
testcase_39 AC 370 ms
60,420 KB
testcase_40 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:61:49: 警告: use of C++23 ‘make_signed_t<size_t>’ integer constant
   61 |             G.add_edge(ac[b/W]-1, acc + ar[b%W]-1z, 1);
      |                                                 ^~

ソースコード

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]-1z, 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