結果
問題 | No.1479 Matrix Eraser |
ユーザー | Ogtsn99 |
提出日時 | 2021-04-23 16:47:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,490 bytes |
コンパイル時間 | 2,829 ms |
コンパイル使用メモリ | 229,268 KB |
実行使用メモリ | 13,880 KB |
最終ジャッジ日時 | 2024-07-04 07:12:48 |
合計ジャッジ時間 | 13,274 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,760 KB |
testcase_01 | AC | 4 ms
6,812 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for(int (i)=0;(i)<(n);(i)++) #define rrep(i, n) for(int (i)=((n)-1);(i)>=0;(i)--) #define itn int #define miele(v) min_element(v.begin(), v.end()) #define maele(v) max_element(v.begin(), v.end()) #define SUM(v) accumulate(v.begin(), v.end(), 0LL) #define lb(a, key) lower_bound(a.begin(),a.end(),key) #define ub(a, key) upper_bound(a.begin(),a.end(),key) #define COUNT(a, key) count(a.begin(), a.end(), key) #define BITCOUNT(x) __builtin_popcount(x) #define pb push_back #define all(x) (x).begin(),(x).end() #define F first #define S second using P = pair<int, int>; using WeightedGraph = vector<vector<P>>; using UnWeightedGraph = vector<vector<int>>; using Real = long double; using Point = complex<Real>; //Point and Vector2d is the same! // p.real() or real(p) -> x軸, p.imag() or imag(p) -> y軸 using Vector2d = complex<Real>; const int MOD = 1000000007; const long long INF = 1LL << 60; const double EPS = 1e-15; const double PI = 3.14159265358979323846; template<typename T> int getIndexOfLowerBound(vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template<typename T> int getIndexOfUpperBound(vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) istream &operator>>(istream &is, Point &p) { Real a, b; is >> a >> b; p = Point(a, b); return is; } template<typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p_var) { is >> p_var.first >> p_var.second; return is; } template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template<typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << pair_var.first << ' ' << pair_var.second; return os; } template<typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) os << vec[i] << ' '; return os; } template<typename T, typename U> ostream &operator<<(ostream &os, vector<pair<T, U>> &vec) { for (int i = 0; i < vec.size(); i++) os << vec[i] << '\n'; return os; } template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &df) { for (auto &vec : df) os << vec; return os; } template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { repi(itr, map_var) { os << *itr << ' '; itr++; itr--; } return os; } template<typename T> ostream &operator<<(ostream &os, set<T> &set_var) { repi(itr, set_var) { os << *itr << ' '; itr++; itr--; } return os; } void print() { cout << endl; } template<class Head, class... Tail> void print(Head &&head, Tail &&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } bool isOk(int mid, int c) { if(3 * mid >= c) return true; else return false; } template <class T> unordered_map <T, int> compression(vector <T> tmp){ sort(tmp.begin(), tmp.end()); tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end()); unordered_map <int, int> ma; for(int i=0;i<tmp.size();++i) ma[tmp[i]] = i; return ma; } struct edge {int to, cap, rev;}; void add_edge(vector <vector<edge>> &G, int from, int to, int cap){ G[from].push_back((edge){to, cap, (int)G[to].size()} ); G[to].push_back((edge){from, 0, (int)G[from].size()-1}); } int dfs(vector <vector<edge>> &G, vector <bool> &used, int v, int t, int f){ if(v==t) return f; used[v] = true; for(int i=0;i<G[v].size();i++){ edge &e = G[v][i]; if(!used[e.to] && e.cap > 0){ int d = dfs(G, used, e.to, t, min(f,e.cap)); if(d>0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(vector <vector<edge>> &G, vector <bool> &used, int s, int t){ int flow = 0; for(;;){ vector <bool> tmp(used.size()); used = tmp; int f = dfs(G, used, s,t,INF); if(f == 0) return flow; flow += f; } } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int h, w; cin>>h>>w; vector<int> numbers(h*w); vector <vector<int>> a(h,vector <int>(w)); rep(i, h) { rep(j, w) { cin>>a[i][j]; numbers[i*w + j] = a[i][j]; } } unordered_map <int, int> ma = compression(numbers); vector <vector<pair <int, int>>> data(ma.size(),vector <pair <int, int>>()); rep(i, h) rep(j, w) data[ma[a[i][j]]].pb({i, j}); int ans = 0; for (int i = 1; i < ma.size(); ++i) { vector <vector<edge>> g(1002); int start = 1000, goal = 1001; for (auto p : data[i]) { add_edge(g, p.first, p.second+500, 1); } for (int i = 0; i < 500; ++i) { add_edge(g, start, i, 1); add_edge(g, i+500, goal, 1); } vector <bool> used(1002); int add = max_flow(g, used, 1000, 1001); ans += add; } print(ans); }