結果
問題 | No.3060 Erase Binary Matrix |
ユーザー |
👑 ![]() |
提出日時 | 2025-03-14 22:51:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 439 ms / 2,000 ms |
コード長 | 1,061 bytes |
コンパイル時間 | 1,076 ms |
コンパイル使用メモリ | 81,576 KB |
実行使用メモリ | 7,328 KB |
最終ジャッジ日時 | 2025-03-14 22:51:23 |
合計ジャッジ時間 | 9,514 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 49 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>using i64 = long long;#define rep(i,n) for(i64 i=0; i<i64(n); i++)const i64 INF = 1001001001001001001;template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }using namespace std;void testcase(){i64 H, W; cin >> H >> W;vector<string> A(H); rep(y,H) cin >> A[y];vector<pair<i64,i64>> nx;rep(a,H) rep(b,H) if(a < b){i64 fl = 0;rep(i,W){if(A[a][i] < A[b][i]) fl |= 1;if(A[a][i] > A[b][i]) fl |= 2;}if(fl == 3) continue;if(fl == 2) nx.push_back({a,b});else nx.push_back({b,a});}vector<i64> dp(H, H-1);rep(i,H){vector<i64> nxdp(H, H-1);for(auto [a,b] : nx) chmin(nxdp[b], dp[a] - 1);swap(dp, nxdp);}cout << *min_element(dp.begin(), dp.end()) << "\n";}int main(){ios::sync_with_stdio(false); cin.tie(nullptr);testcase();return 0;}