結果
問題 | No.1479 Matrix Eraser |
ユーザー | tokusakurai |
提出日時 | 2021-04-16 20:46:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,650 ms / 3,000 ms |
コード長 | 3,157 bytes |
コンパイル時間 | 2,573 ms |
コンパイル使用メモリ | 218,116 KB |
実行使用メモリ | 23,808 KB |
最終ジャッジ日時 | 2024-07-02 23:21:26 |
合計ジャッジ時間 | 33,341 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
14,976 KB |
testcase_01 | AC | 10 ms
14,916 KB |
testcase_02 | AC | 11 ms
14,976 KB |
testcase_03 | AC | 12 ms
14,976 KB |
testcase_04 | AC | 11 ms
14,772 KB |
testcase_05 | AC | 12 ms
14,976 KB |
testcase_06 | AC | 11 ms
14,952 KB |
testcase_07 | AC | 248 ms
16,000 KB |
testcase_08 | AC | 407 ms
16,768 KB |
testcase_09 | AC | 754 ms
18,432 KB |
testcase_10 | AC | 1,686 ms
21,244 KB |
testcase_11 | AC | 817 ms
18,944 KB |
testcase_12 | AC | 99 ms
16,256 KB |
testcase_13 | AC | 246 ms
16,640 KB |
testcase_14 | AC | 112 ms
16,256 KB |
testcase_15 | AC | 24 ms
15,212 KB |
testcase_16 | AC | 203 ms
16,456 KB |
testcase_17 | AC | 2,132 ms
22,208 KB |
testcase_18 | AC | 2,142 ms
22,272 KB |
testcase_19 | AC | 2,144 ms
22,272 KB |
testcase_20 | AC | 2,135 ms
22,128 KB |
testcase_21 | AC | 2,147 ms
22,272 KB |
testcase_22 | AC | 2,134 ms
22,248 KB |
testcase_23 | AC | 2,163 ms
22,272 KB |
testcase_24 | AC | 2,123 ms
22,208 KB |
testcase_25 | AC | 2,136 ms
22,168 KB |
testcase_26 | AC | 2,161 ms
22,200 KB |
testcase_27 | AC | 53 ms
19,076 KB |
testcase_28 | AC | 52 ms
18,932 KB |
testcase_29 | AC | 52 ms
18,840 KB |
testcase_30 | AC | 52 ms
18,944 KB |
testcase_31 | AC | 53 ms
19,072 KB |
testcase_32 | AC | 33 ms
18,688 KB |
testcase_33 | AC | 34 ms
18,844 KB |
testcase_34 | AC | 32 ms
18,968 KB |
testcase_35 | AC | 33 ms
18,844 KB |
testcase_36 | AC | 33 ms
18,676 KB |
testcase_37 | AC | 30 ms
18,068 KB |
testcase_38 | AC | 39 ms
18,092 KB |
testcase_39 | AC | 2,650 ms
23,808 KB |
testcase_40 | AC | 11 ms
14,916 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; struct Bipartite_Matching{ vector<vector<int>> es; vector<int> d, match; vector<bool> used, used2; const int n, m; Bipartite_Matching(int n, int m) : es(n), d(n), match(m), used(n), used2(n), n(n), m(m) {} void add_edge(int u, int v){ es[u].push_back(v); } void _bfs(){ fill(begin(d), end(d), -1); queue<int> que; for(int i = 0; i < n; i++){ if(!used[i]) que.emplace(i), d[i] = 0; } while(!que.empty()){ int i = que.front(); que.pop(); for(auto &e: es[i]){ int j = match[e]; if(j != -1 && d[j] == -1){ que.emplace(j), d[j] = d[i]+1; } } } } bool _dfs(int now){ used2[now] = true; for(auto &e: es[now]){ int u = match[e]; if(u == -1 || (!used2[u] && d[u] == d[now]+1 && _dfs(u))){ match[e] = now, used[now] = true; return true; } } return false; } int bipartite_matching(){ fill(begin(match), end(match), -1), fill(begin(used), end(used), false); int ret = 0; while(true){ _bfs(); fill(begin(used2), end(used2), false); int flow = 0; for(int i = 0; i < n; i++){ if(!used[i] && _dfs(i)) flow++; } if(flow == 0) break; ret += flow; } return ret; } }; int main(){ int H, W; cin >> H >> W; vector<vector<int>> A(H, vector<int>(W)); rep(i, H){ rep(j, W){ cin >> A[i][j]; } } int MAX = 500000; vector<vector<pii>> ps(MAX+1); rep(i, H){ rep(j, W){ ps[A[i][j]].eb(i, j); } } vector<int> cx(H, 0), cy(W, 0); int sx = 0, sy = 0; ll ans = 0; Bipartite_Matching G(H, W); rep3(i, MAX, 1){ if(ps[i].empty()) continue; each(e, ps[i]){ auto [x, y] = e; G.add_edge(x, y); } ans += G.bipartite_matching(); rep(i, H) G.es[i].clear(); } cout << ans << '\n'; }