結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-16 22:32:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,799 bytes |
| 記録 | |
| コンパイル時間 | 3,711 ms |
| コンパイル使用メモリ | 189,432 KB |
| 実行使用メモリ | 71,168 KB |
| 最終ジャッジ日時 | 2024-07-03 02:40:16 |
| 合計ジャッジ時間 | 11,638 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 TLE * 1 -- * 30 |
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
45 | for(auto [a, as] : A) {
| ^
ソースコード
#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;
map<int, bitset<500>> Ac, Ar;
map<int, 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);
Ac[a].set(i);
Ar[a].set(j);
}
}
int ans = 0;
for(auto [a, as] : A) {
if(a == 0) continue;
int acc = 0, arc = 0;
vector<int> ac(H, -1), ar(W, -1);
for(int i = 0; i < H; i++) {
if(Ac[a].test(i)) ac[i] = acc++;
}
for(int j = 0; j < W; j++) {
if(Ar[a].test(j)) ar[j] = 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], acc + ar[b%W], 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;
}