結果

問題 No.1479 Matrix Eraser
ユーザー KKT89KKT89
提出日時 2021-04-16 20:24:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,578 bytes
コンパイル時間 3,198 ms
コンパイル使用メモリ 230,068 KB
実行使用メモリ 31,876 KB
最終ジャッジ日時 2023-09-15 21:06:29
合計ジャッジ時間 11,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 28 ms
6,608 KB
testcase_08 AC 58 ms
8,892 KB
testcase_09 AC 157 ms
14,524 KB
testcase_10 AC 340 ms
22,680 KB
testcase_11 AC 187 ms
16,344 KB
testcase_12 AC 36 ms
7,632 KB
testcase_13 AC 56 ms
8,912 KB
testcase_14 AC 41 ms
7,724 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 43 ms
8,204 KB
testcase_17 AC 421 ms
26,096 KB
testcase_18 AC 431 ms
25,980 KB
testcase_19 AC 426 ms
26,224 KB
testcase_20 AC 430 ms
26,008 KB
testcase_21 AC 432 ms
26,240 KB
testcase_22 AC 417 ms
26,052 KB
testcase_23 AC 430 ms
25,964 KB
testcase_24 AC 443 ms
25,968 KB
testcase_25 AC 443 ms
25,988 KB
testcase_26 AC 436 ms
26,012 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 22 ms
8,180 KB
testcase_38 AC 56 ms
6,280 KB
testcase_39 AC 244 ms
31,876 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<vector<int>> a(n,vector<int>(m));
    map<int,vector<pair<int,int>>> mp;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
            mp[a[i][j]].push_back({i,j});
        }
    }
    int res=0;
    vector<int> v(n),vv(m);
    vector<int> c(n),d(m);
    for(auto p:mp){
        if(p.first==0)continue;
        fill(v.begin(), v.end(),0);
        fill(vv.begin(), vv.end(),0);
        fill(c.begin(), c.end(),0);
        fill(d.begin(), d.end(),0);
        for(auto pp:p.second){
            v[pp.first]++;
            vv[pp.second]++;
        }
        priority_queue<pair<int,pair<int,int>>> pq;
        for(auto pp:p.second){
            pq.push(make_pair(v[pp.first]+vv[pp.second]-1,pp));
        }
        while(pq.size()){
            auto pp=pq.top(); pq.pop();
            if(c[pp.second.first] or d[pp.second.second])continue;
            if(v[pp.second.first]>=vv[pp.second.second]){
                c[pp.second.first]=1;
                res++;
                vv[pp.second.second]--;
            }
            else{
                d[pp.second.second]=1;
                res++;
                v[pp.second.first]--;
            }
        }
    }
    cout << res << endl;
}
0