結果
問題 | No.1479 Matrix Eraser |
ユーザー | hir355 |
提出日時 | 2021-04-16 22:30:13 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 279 ms / 3,000 ms |
コード長 | 2,978 bytes |
コンパイル時間 | 2,481 ms |
コンパイル使用メモリ | 220,132 KB |
実行使用メモリ | 23,720 KB |
最終ジャッジ日時 | 2023-09-16 01:26:24 |
合計ジャッジ時間 | 9,545 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
14,904 KB |
testcase_01 | AC | 6 ms
14,740 KB |
testcase_02 | AC | 7 ms
14,844 KB |
testcase_03 | AC | 7 ms
14,556 KB |
testcase_04 | AC | 6 ms
15,040 KB |
testcase_05 | AC | 7 ms
14,652 KB |
testcase_06 | AC | 7 ms
14,756 KB |
testcase_07 | AC | 38 ms
15,692 KB |
testcase_08 | AC | 60 ms
16,584 KB |
testcase_09 | AC | 120 ms
18,340 KB |
testcase_10 | AC | 229 ms
20,968 KB |
testcase_11 | AC | 145 ms
18,836 KB |
testcase_12 | AC | 48 ms
15,924 KB |
testcase_13 | AC | 59 ms
16,372 KB |
testcase_14 | AC | 48 ms
16,320 KB |
testcase_15 | AC | 16 ms
15,208 KB |
testcase_16 | AC | 52 ms
16,152 KB |
testcase_17 | AC | 275 ms
22,068 KB |
testcase_18 | AC | 275 ms
22,008 KB |
testcase_19 | AC | 273 ms
21,968 KB |
testcase_20 | AC | 276 ms
21,968 KB |
testcase_21 | AC | 275 ms
22,076 KB |
testcase_22 | AC | 275 ms
21,912 KB |
testcase_23 | AC | 270 ms
21,968 KB |
testcase_24 | AC | 275 ms
22,068 KB |
testcase_25 | AC | 276 ms
22,072 KB |
testcase_26 | AC | 279 ms
22,048 KB |
testcase_27 | AC | 134 ms
18,844 KB |
testcase_28 | AC | 136 ms
19,028 KB |
testcase_29 | AC | 134 ms
19,016 KB |
testcase_30 | AC | 133 ms
18,948 KB |
testcase_31 | AC | 138 ms
19,104 KB |
testcase_32 | AC | 78 ms
23,164 KB |
testcase_33 | AC | 75 ms
23,240 KB |
testcase_34 | AC | 78 ms
23,372 KB |
testcase_35 | AC | 77 ms
23,280 KB |
testcase_36 | AC | 77 ms
23,288 KB |
testcase_37 | AC | 39 ms
15,668 KB |
testcase_38 | AC | 142 ms
18,112 KB |
testcase_39 | AC | 263 ms
23,720 KB |
testcase_40 | AC | 7 ms
14,852 KB |
ソースコード
#include <atcoder/maxflow> #include <bits/stdc++.h> using namespace std; using namespace atcoder; const long long INF_LL = 2000000000000000000LL; const int INF = 2000000000; const long long MOD = 1000000007; #define ll long long #define all(x) x.begin(), x.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) // typedef float double; // typedef priority_queue prique; typedef pair<ll, ll> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; typedef vector<vi> matrix; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; int sign[2] = {1, -1}; template <class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } ll modpow(ll a, ll b, ll m) { if(b == 0) return 1; ll t = modpow(a, b / 2, m); if(b & 1) { return (t * t % m) * a % m; } else { return t * t % m; } } struct edge { int to; ll cost; edge(int t, ll c) { to = t, cost = c; } }; typedef vector<vector<edge>> graph; // using mint = modint998244353; 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]; vector<vector<pair<int, int>>> t(500000); rep(i, h){ rep(j, w){ if(a[i][j] > 0) { t[a[i][j] - 1].push_back({i, j}); } } } int ans = 0; for(int i = 499999; i >= 0; i--){ if(t[i].size() > 0){ int tmp1; sort(all(t[i])); int tmp = t[i][0].first; t[i][0].first = 0; rep(j, t[i].size() - 1){ if(tmp < t[i][j + 1].first){ tmp = t[i][j + 1].first; t[i][j + 1].first = t[i][j].first + 1; }else{ t[i][j + 1].first = t[i][j].first; } } tmp1 = t[i][t[i].size()-1].first + 1; int tmp2; sort(all(t[i]), [](auto x, auto y){return x.second < y.second;}); tmp = t[i][0].second; t[i][0].second = 0; rep(j, t[i].size() - 1){ if(tmp < t[i][j + 1].second){ tmp = t[i][j + 1].second; t[i][j + 1].second = t[i][j].second + 1; }else{ t[i][j + 1].second = t[i][j].second; } } tmp2 = t[i][t[i].size()-1].second + 1; mf_graph<int> g(tmp1 + tmp2 + 2); rep(j, tmp1) g.add_edge(tmp1 + tmp2, j, 1); rep(j, tmp2) g.add_edge(j + tmp1, tmp1 + tmp2 + 1, 1); rep(j, t[i].size()){ g.add_edge(t[i][j].first, t[i][j].second + tmp1, 1); } ans += g.flow(tmp1 + tmp2, tmp1 + tmp2 + 1); } } cout << ans << endl; }