結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
26,476 KB
testcase_01 AC 55 ms
26,400 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 148 ms
29,044 KB
testcase_08 AC 176 ms
30,380 KB
testcase_09 AC 241 ms
33,272 KB
testcase_10 AC 344 ms
38,036 KB
testcase_11 AC 265 ms
34,376 KB
testcase_12 AC 155 ms
28,900 KB
testcase_13 AC 168 ms
29,968 KB
testcase_14 AC 157 ms
29,040 KB
testcase_15 AC 111 ms
27,276 KB
testcase_16 AC 143 ms
29,632 KB
testcase_17 AC 397 ms
39,964 KB
testcase_18 AC 400 ms
39,932 KB
testcase_19 AC 395 ms
39,940 KB
testcase_20 AC 396 ms
39,924 KB
testcase_21 AC 395 ms
39,952 KB
testcase_22 AC 391 ms
39,860 KB
testcase_23 AC 392 ms
39,928 KB
testcase_24 AC 392 ms
39,812 KB
testcase_25 AC 396 ms
39,956 KB
testcase_26 AC 395 ms
39,932 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 214 ms
29,668 KB
testcase_33 AC 213 ms
29,624 KB
testcase_34 AC 213 ms
29,632 KB
testcase_35 AC 214 ms
29,604 KB
testcase_36 AC 213 ms
29,620 KB
testcase_37 AC 137 ms
29,692 KB
testcase_38 AC 217 ms
29,808 KB
testcase_39 AC 325 ms
43,308 KB
testcase_40 AC 21 ms
26,500 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(w, { 0, 1 });
    std::vector<S> uw(h, { 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, w, 0);
        segw.apply(0, h, 0);
        rep(j, SZ(sch[i])){
            int p = sch[i][j] % w;
            segh.apply(p, p + 1, 1);
        }
        rep(j, SZ(scw[i])) {
            int p = scw[i][j] % h;
            segw.apply(p, p + 1, 1);
        }
        res += min(segh.all_prod().value, segw.all_prod().value);
    }
    cout << res << endl;
}
0