結果

問題 No.1479 Matrix Eraser
ユーザー pockynypockyny
提出日時 2021-04-16 20:38:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,091 ms / 3,000 ms
コード長 1,024 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 104,380 KB
実行使用メモリ 75,528 KB
最終ジャッジ日時 2023-09-15 21:34:01
合計ジャッジ時間 17,387 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 52 ms
12,252 KB
testcase_08 AC 96 ms
18,424 KB
testcase_09 AC 300 ms
35,104 KB
testcase_10 AC 1,091 ms
63,284 KB
testcase_11 AC 611 ms
39,684 KB
testcase_12 AC 80 ms
14,048 KB
testcase_13 AC 119 ms
17,976 KB
testcase_14 AC 87 ms
14,788 KB
testcase_15 AC 14 ms
5,808 KB
testcase_16 AC 101 ms
16,000 KB
testcase_17 AC 802 ms
74,880 KB
testcase_18 AC 765 ms
75,300 KB
testcase_19 AC 767 ms
74,880 KB
testcase_20 AC 792 ms
75,528 KB
testcase_21 AC 793 ms
74,676 KB
testcase_22 AC 782 ms
75,512 KB
testcase_23 AC 754 ms
74,664 KB
testcase_24 AC 747 ms
75,212 KB
testcase_25 AC 754 ms
74,844 KB
testcase_26 AC 782 ms
75,336 KB
testcase_27 AC 377 ms
28,592 KB
testcase_28 AC 390 ms
28,528 KB
testcase_29 AC 394 ms
28,484 KB
testcase_30 AC 401 ms
28,260 KB
testcase_31 AC 384 ms
28,192 KB
testcase_32 AC 64 ms
15,208 KB
testcase_33 AC 63 ms
15,060 KB
testcase_34 AC 63 ms
15,036 KB
testcase_35 AC 64 ms
14,812 KB
testcase_36 AC 63 ms
15,036 KB
testcase_37 AC 36 ms
4,532 KB
testcase_38 AC 443 ms
75,392 KB
testcase_39 AC 407 ms
75,444 KB
testcase_40 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/maxflow>
#include <utility>
#include <map>

using namespace std;
using namespace atcoder;
int a[510][510];
map<int,int> mp1[510];
map<int,int> mp2[510];
int main(){
    int i,j,h,w; cin >> h >> w;
    int now = 0;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> a[i][j];
          	if(a[i][j]==0) continue;
            if(mp1[i].find(a[i][j])==mp1[i].end()){
                mp1[i][a[i][j]] = now; now++;
            }
            if(mp2[j].find(a[i][j])==mp2[j].end()){
                mp2[j][a[i][j]] = now; now++;
            }
        }
    }
    mf_graph<int> g(now + 2);
    int s = now,t = now + 1;
  	for(i=0;i<h;i++){
  		for(auto x:mp1[i]) g.add_edge(s,x.second,1);
    }
  	for(j=0;j<w;j++){
		for(auto x:mp2[j]) g.add_edge(x.second,t,1);
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
          	if(a[i][j]==0) continue;
            g.add_edge(mp1[i][a[i][j]],mp2[j][a[i][j]],1);
        }
    }
    cout << g.flow(s,t) << endl;
}
0