結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-16 22:29:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,896 bytes |
| 記録 | |
| コンパイル時間 | 2,715 ms |
| コンパイル使用メモリ | 222,292 KB |
| 最終ジャッジ日時 | 2025-01-20 20:12:48 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int128 = __int128_t;
using int64 = long long;
using int32 = int;
using uint128 = __uint128_t;
using uint64 = unsigned long long;
using uint32 = unsigned int;
#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;
constexpr int64 MOD = 1'000'000'000LL + 7; //'
constexpr int64 MOD2 = 998244353;
constexpr int64 HIGHINF = 1'000'000'000'000'000'000LL;
constexpr int64 LOWINF = 1'000'000'000'000'000LL; //'
constexpr long double PI = 3.1415926535897932384626433L;
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const deque<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
inline constexpr int msb(int x) {return x?31-__builtin_clz(x):-1;}
inline constexpr int64 ceil_div(const int64 a,const int64 b) {return (a+(b-1))/b;}// return ceil(a/b)
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}
/*
* @title Zarts - 座標圧縮
* @docs md/util/Zarts.md
*/
template<class T> class Zarts{
vector<T> value;
map<T,int> key;
size_t sz;
public:
vector<int> compressed;
Zarts(const vector<T> & ar, int light_flag = 0, T pre=-1) : compressed(ar.size()) {
if(!light_flag) {
for (auto &e : ar) key[e];
int cnt=0;
for (auto &e : key) e.second = cnt++;
for (int i=0;i<ar.size();++i) compressed[i]=key[ar[i]];
value.resize(key.size());
for (auto &e : key) value[e.second] = e.first;
sz = cnt;
}
else {
vector<pair<int,int>> ord(ar.size());
for(int i=0;i<ar.size();++i) ord[i]={ar[i],i};
sort(ord.begin(),ord.end());
int cnt=-1;
for(int i=0;i<ar.size();++i) {
if(pre < ord[i].first) cnt++;
compressed[ord[i].second] = cnt;
pre = ord[i].first;
}
sz = cnt+1;
}
}
T get_value(int key) {
return value[key];
}
int get_key(T value) {
assert(key.count(value));
return key[value];
}
size_t size() {
return sz;
}
};
int solve(vector<pair<int,int>> vp) {
int n = vp.size();
vector<int> Y(n),X(n);
for(int i=0;i<n;++i) Y[i] = vp[i].first;
for(int i=0;i<n;++i) X[i] = vp[i].second;
Zarts<int> ZY(Y),ZX(X);
int H = ZY.size();
int W = ZX.size();
vector<int> A(H,0),B(W,0);
for(int y:ZY.compressed) A[y]++;
for(int x:ZX.compressed) B[x]++;
priority_queue_reverse<pair<int,pair<int,int>>> pq;
for(int y=0;y<H;++y) pq.push({A[y],{y,0}});
for(int x=0;x<W;++x) pq.push({B[x],{x,1}});
vector<int> C(H,1),D(W,1);
int res=0;
while(pq.size()) {
auto p = pq.top(); pq.pop();
if(p.second.second == 0) {
int y = p.second.first;
int flg = 1;
for(int i=0;i<n;++i) {
if(ZY.compressed[i]!=y) continue;
int x = ZX.compressed[i];
flg &= D[x];
}
if(flg) C[y] = 0;
else res++;
}
else {
int x = p.second.first;
int flg = 1;
for(int i=0;i<n;++i) {
if(ZX.compressed[i]!=x) continue;
int y = ZY.compressed[i];
flg &= C[y];
}
if(flg) D[x] = 0;
else res++;
}
}
return res;
}
/**
* @url
* @est
*/
int main() {
cin.tie(0);ios::sync_with_stdio(false);
int H,W; cin >> H >> W;
int M = 500010;
vector<vector<pair<int,int>>> vvp(M);
for(int i=0;i<H;++i) {
for(int j=0;j<W;++j) {
int a; cin >> a;
vvp[a].push_back({i,j});
}
}
int ans = 0;
for(int n=1;n<M;++n) {
if(vvp[n].empty()) continue;
int cnt = solve(vvp[n]);
ans += cnt;
}
cout << ans << endl;
return 0;
}