結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
Be11T_
|
| 提出日時 | 2021-04-16 21:31:13 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,174 bytes |
| 記録 | |
| コンパイル時間 | 7,247 ms |
| コンパイル使用メモリ | 255,336 KB |
| 最終ジャッジ日時 | 2025-01-20 19:32:29 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 10 |
ソースコード
#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;
}
Be11T_