結果
| 問題 |
No.2473 Fraises dans une boîte
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-14 00:06:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,547 bytes |
| コンパイル時間 | 2,093 ms |
| コンパイル使用メモリ | 198,700 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-05-14 00:06:58 |
| 合計ジャッジ時間 | 46,830 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 WA * 55 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 310;
int n, m, a[maxn][maxn], f[maxn][maxn], cnt[maxn][maxn], rd[maxn][maxn];
int calc(int xl, int xr, int yl, int yr) {
return cnt[xr][yr] - cnt[xl - 1][yr] - cnt[xr][yl - 1] + cnt[xl - 1][yl - 1];
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m;
rep (i, 1, n) rep (j, 1, m) cin >> a[i][j];
rep (i, 1, n) rep (j, 1, m) cnt[i][j] = !a[i][j];
rep (i, 1, n) rep (j, 1, m) cnt[i][j] += cnt[i - 1][j];
rep (i, 1, n) rep (j, 1, m) cnt[i][j] += cnt[i][j - 1];
rep (i, 1, n) rep (j, 1, m) rd[i][j] = a[i][j];
per (i, n, 1) per (j, m, 1) rd[i][j] += rd[i + 1][j];
per (i, n, 1) per (j, m, 1) rd[i][j] += rd[i][j + 1];
per (i, n, 1) per (j, m, 1) {
if (calc(i, i, j, m) == m - j + 1) { f[i][j] = f[i + 1][j]; continue; }
if (calc(i, n, j, j) == n - i + 1) { f[i][j] = f[i][j + 1]; continue; }
f[i][j] = calc(i, n, j, m);
if (!rd[i][j]) f[i][j] = 0;
rep (x, i, n + 1) rep (y, j, m + 1) if (!rd[x][y]) chkmn(f[i][j], f[x][j] + f[i][y] + calc(i, x - 1, j, y - 1));
}
cout << f[1][1] << '\n';
}