結果

問題 No.1479 Matrix Eraser
ユーザー kakira9618kakira9618
提出日時 2021-04-16 20:47:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 173,416 KB
実行使用メモリ 23,528 KB
最終ジャッジ日時 2023-09-15 21:56:36
合計ジャッジ時間 15,454 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
14,568 KB
testcase_01 AC 36 ms
14,624 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 197 ms
15,924 KB
testcase_08 AC 214 ms
16,428 KB
testcase_09 AC 293 ms
18,328 KB
testcase_10 AC 407 ms
20,844 KB
testcase_11 AC 324 ms
19,004 KB
testcase_12 AC 212 ms
16,024 KB
testcase_13 AC 188 ms
16,400 KB
testcase_14 AC 208 ms
16,144 KB
testcase_15 AC 108 ms
15,156 KB
testcase_16 AC 178 ms
16,220 KB
testcase_17 AC 446 ms
22,212 KB
testcase_18 AC 448 ms
22,032 KB
testcase_19 AC 454 ms
21,960 KB
testcase_20 AC 452 ms
21,976 KB
testcase_21 AC 450 ms
21,948 KB
testcase_22 AC 449 ms
21,944 KB
testcase_23 AC 449 ms
21,960 KB
testcase_24 AC 446 ms
21,980 KB
testcase_25 AC 443 ms
21,896 KB
testcase_26 AC 452 ms
22,096 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 353 ms
17,912 KB
testcase_33 AC 352 ms
17,772 KB
testcase_34 AC 353 ms
18,016 KB
testcase_35 AC 351 ms
17,772 KB
testcase_36 AC 356 ms
17,864 KB
testcase_37 AC 358 ms
17,860 KB
testcase_38 AC 381 ms
17,856 KB
testcase_39 AC 417 ms
23,528 KB
testcase_40 AC 29 ms
14,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int H, W;
    cin >> H >> W;
    constexpr int size = 500001;
    vector<vector<int>> A(H, vector<int>(W));
    vector<vector<pii>> X(size);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            X[A[i][j]].push_back({i, j});
        }
    }

    int ans = 0;
    for (int a = 1; a < size; a++) {
        vector<int> cntH(H), cntW(W);
        for (int k = 0; k < X[a].size(); k++) {
            int i = X[a][k].first, j = X[a][k].second;
            cntH[i]++; cntW[j]++;
        }
        int cH = 0, cW = 0;
        for (int i = 0; i < H; i++) {
            if (cntH[i]) cH++;
        }
        for (int j = 0; j < W; j++) {
            if (cntW[j]) cW++;
        }
        ans += min(cH, cW);
    }

    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}
0