結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-16 23:29:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 478 ms / 3,000 ms |
| コード長 | 1,693 bytes |
| コンパイル時間 | 3,908 ms |
| コンパイル使用メモリ | 195,872 KB |
| 最終ジャッジ日時 | 2025-01-20 20:47:09 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
コンパイルメッセージ
main.cpp:61:49: warning: 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);
| ^~
ソースコード
#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;
}