結果
問題 | No.1479 Matrix Eraser |
ユーザー | ningenMe |
提出日時 | 2021-04-16 22:29:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,896 bytes |
コンパイル時間 | 3,385 ms |
コンパイル使用メモリ | 232,524 KB |
実行使用メモリ | 22,736 KB |
最終ジャッジ日時 | 2024-07-03 02:35:05 |
合計ジャッジ時間 | 12,723 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
14,924 KB |
testcase_01 | AC | 12 ms
14,908 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 12 ms
14,892 KB |
testcase_06 | AC | 11 ms
14,976 KB |
testcase_07 | AC | 39 ms
15,872 KB |
testcase_08 | AC | 58 ms
16,512 KB |
testcase_09 | AC | 112 ms
17,920 KB |
testcase_10 | AC | 200 ms
20,276 KB |
testcase_11 | AC | 115 ms
18,560 KB |
testcase_12 | AC | 38 ms
16,000 KB |
testcase_13 | AC | 49 ms
16,420 KB |
testcase_14 | AC | 39 ms
16,104 KB |
testcase_15 | AC | 14 ms
15,232 KB |
testcase_16 | AC | 43 ms
16,128 KB |
testcase_17 | AC | 211 ms
21,220 KB |
testcase_18 | AC | 212 ms
21,120 KB |
testcase_19 | AC | 227 ms
21,228 KB |
testcase_20 | AC | 240 ms
21,164 KB |
testcase_21 | AC | 239 ms
21,156 KB |
testcase_22 | AC | 241 ms
21,228 KB |
testcase_23 | AC | 246 ms
21,248 KB |
testcase_24 | AC | 248 ms
21,248 KB |
testcase_25 | AC | 243 ms
21,248 KB |
testcase_26 | AC | 243 ms
21,280 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
17,068 KB |
testcase_38 | AC | 460 ms
17,136 KB |
testcase_39 | AC | 196 ms
22,736 KB |
testcase_40 | AC | 9 ms
14,976 KB |
ソースコード
#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; }