結果

問題 No.1479 Matrix Eraser
ユーザー ningenMeningenMe
提出日時 2021-04-16 22:29:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,896 bytes
コンパイル時間 2,865 ms
コンパイル使用メモリ 229,820 KB
実行使用メモリ 22,424 KB
最終ジャッジ日時 2023-09-16 01:24:43
合計ジャッジ時間 11,984 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
14,816 KB
testcase_01 AC 7 ms
15,012 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 7 ms
14,912 KB
testcase_06 AC 7 ms
14,656 KB
testcase_07 AC 33 ms
15,624 KB
testcase_08 AC 50 ms
16,236 KB
testcase_09 AC 98 ms
17,784 KB
testcase_10 AC 179 ms
20,148 KB
testcase_11 AC 114 ms
18,344 KB
testcase_12 AC 39 ms
15,848 KB
testcase_13 AC 51 ms
16,140 KB
testcase_14 AC 40 ms
15,888 KB
testcase_15 AC 14 ms
14,956 KB
testcase_16 AC 46 ms
16,024 KB
testcase_17 AC 213 ms
20,864 KB
testcase_18 AC 215 ms
20,908 KB
testcase_19 AC 213 ms
21,020 KB
testcase_20 AC 215 ms
20,816 KB
testcase_21 AC 214 ms
20,896 KB
testcase_22 AC 214 ms
20,936 KB
testcase_23 AC 213 ms
20,868 KB
testcase_24 AC 215 ms
20,920 KB
testcase_25 AC 214 ms
20,964 KB
testcase_26 AC 214 ms
21,224 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 24 ms
16,900 KB
testcase_38 AC 450 ms
16,984 KB
testcase_39 AC 193 ms
22,424 KB
testcase_40 AC 7 ms
14,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0