結果

問題 No.1479 Matrix Eraser
ユーザー Be11T_Be11T_
提出日時 2021-04-16 21:16:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,182 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 265,356 KB
実行使用メモリ 43,400 KB
最終ジャッジ日時 2023-09-15 23:13:07
合計ジャッジ時間 15,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
26,552 KB
testcase_01 AC 127 ms
26,560 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 155 ms
29,276 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 377 ms
39,944 KB
testcase_18 AC 376 ms
40,012 KB
testcase_19 AC 376 ms
39,952 KB
testcase_20 AC 381 ms
39,908 KB
testcase_21 AC 378 ms
39,888 KB
testcase_22 AC 382 ms
39,880 KB
testcase_23 AC 369 ms
40,012 KB
testcase_24 AC 378 ms
39,968 KB
testcase_25 AC 379 ms
39,888 KB
testcase_26 AC 375 ms
40,056 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 219 ms
29,624 KB
testcase_33 AC 216 ms
29,704 KB
testcase_34 AC 218 ms
29,568 KB
testcase_35 AC 216 ms
29,564 KB
testcase_36 AC 216 ms
29,612 KB
testcase_37 AC 144 ms
29,916 KB
testcase_38 AC 222 ms
30,016 KB
testcase_39 AC 322 ms
43,400 KB
testcase_40 AC 126 ms
26,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, m, n) for(ll i = m; i <= n; i++)
#define rrep(i, m, n) for(ll i = m; i >= n; i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SZ(a) ((ll)(a).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, 1, -1 };
const int inf = 1e9 + 1;
const ll INF = 1e18 + 1;
const double pi = acos(-1);

using Graph = vector<vector<int>>;
Graph G;

ll powll(ll a, ll b) {
    ll ret = 1;
    rep(i, b) ret *= a;

    return ret;
}

//typedef atcoder::modint1000000007 mint;
//typedef atcoder::modint998244353 mint;
//typedef modint mint;
struct S {
    long long value;
    int size;
};
using F = long long;

const F ID = 8e18;

S op(S a, S b) { return { a.value + b.value, a.size + b.size }; }
S e() { return { 0, 0 }; }
S mapping(F f, S x) {
    if (f != ID) x.value = f * x.size;
    return x;
}
F composition(F f, F g) { return (f == ID ? g : f); }
F id() { return ID; }

int a[510][510];


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w; cin >> h >> w;
    rep(i, h)rep(j, w) cin >> a[i][j];

    vector<vector<int>> sch(500001), scw(500001);

    rep(i, h)rep(j, w) {
        sch[a[i][j]].push_back(i * w + j);
        scw[a[i][j]].push_back(i + j * h);
    }

    int res = 0;
    std::vector<S> uh(501, { 0, 1 });
    std::vector<S> uw(501, { 0, 1 });

    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> segh(uh);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> segw(uw);
    rep2(i, 1, 500000) {
        segh.apply(0, 501, 0);
        segw.apply(0, 501, 0);
        rep(j, SZ(sch[i])){
            int p = sch[i][j] % h;
            segh.apply(p, p + 1, 1);
        }
        rep(j, SZ(scw[i])) {
            int p = scw[i][j] % w;
            segw.apply(p, p + 1, 1);
        }
        res += min(segh.all_prod().value, segw.all_prod().value);
    }
    cout << res << endl;
}
0