結果
問題 | No.1479 Matrix Eraser |
ユーザー | KKT89 |
提出日時 | 2021-04-16 21:00:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 520 ms / 3,000 ms |
コード長 | 1,542 bytes |
コンパイル時間 | 6,084 ms |
コンパイル使用メモリ | 300,556 KB |
実行使用メモリ | 31,784 KB |
最終ジャッジ日時 | 2023-09-15 22:28:31 |
合計ジャッジ時間 | 15,857 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 44 ms
6,664 KB |
testcase_08 | AC | 80 ms
9,080 KB |
testcase_09 | AC | 188 ms
14,480 KB |
testcase_10 | AC | 418 ms
22,752 KB |
testcase_11 | AC | 240 ms
16,484 KB |
testcase_12 | AC | 59 ms
7,552 KB |
testcase_13 | AC | 81 ms
8,928 KB |
testcase_14 | AC | 59 ms
7,712 KB |
testcase_15 | AC | 12 ms
4,380 KB |
testcase_16 | AC | 67 ms
8,248 KB |
testcase_17 | AC | 507 ms
26,160 KB |
testcase_18 | AC | 498 ms
26,100 KB |
testcase_19 | AC | 493 ms
26,068 KB |
testcase_20 | AC | 481 ms
26,076 KB |
testcase_21 | AC | 487 ms
26,112 KB |
testcase_22 | AC | 488 ms
26,048 KB |
testcase_23 | AC | 497 ms
26,076 KB |
testcase_24 | AC | 520 ms
26,036 KB |
testcase_25 | AC | 506 ms
26,056 KB |
testcase_26 | AC | 494 ms
26,084 KB |
testcase_27 | AC | 136 ms
7,304 KB |
testcase_28 | AC | 137 ms
7,416 KB |
testcase_29 | AC | 136 ms
7,388 KB |
testcase_30 | AC | 136 ms
7,304 KB |
testcase_31 | AC | 137 ms
7,044 KB |
testcase_32 | AC | 67 ms
13,508 KB |
testcase_33 | AC | 69 ms
13,560 KB |
testcase_34 | AC | 69 ms
13,484 KB |
testcase_35 | AC | 68 ms
13,508 KB |
testcase_36 | AC | 68 ms
13,596 KB |
testcase_37 | AC | 20 ms
7,956 KB |
testcase_38 | AC | 145 ms
6,408 KB |
testcase_39 | AC | 361 ms
31,784 KB |
testcase_40 | AC | 2 ms
4,376 KB |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } // N使ってる状態 0 // M使ってる状態 1 int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector<vector<int>> a(n,vector<int>(m)); map<int,vector<pair<int,int>>> mp; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin >> a[i][j]; mp[a[i][j]].push_back({i,j}); } } int res=0; for(auto p:mp){ if(p.first==0)continue; vector<int> v,vv; for(auto pp:p.second){ v.push_back(pp.first); vv.push_back(pp.second); } sort(v.begin(), v.end()); sort(vv.begin(), vv.end()); v.erase(unique(v.begin(), v.end()),v.end()); vv.erase(unique(vv.begin(), vv.end()),vv.end()); int N=v.size(),M=vv.size(); mf_graph<int> g(N+M+2); int S=N+M,T=N+M+1; for(int i=0;i<N;i++){ g.add_edge(i,T,1); } for(int i=0;i<M;i++){ g.add_edge(S,N+i,1); } for(auto pp:p.second){ g.add_edge(N+(lower_bound(vv.begin(), vv.end(),pp.second)-vv.begin()),(lower_bound(v.begin(), v.end(),pp.first)-v.begin()),1e9); } res+=g.flow(S,T); } cout << res << endl; }