結果

問題 No.2473 Fraises dans une boîte
ユーザー 👑 tute7627tute7627
提出日時 2023-07-23 12:31:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,546 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 206,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:23:41
合計ジャッジ時間 8,283 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  assert(1 <= H && H <= 22);
  assert(1 <= W && W <= 22);

  vector S(H, vector(W, 0));
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> S[i][j];
      assert(S[i][j] == 0 || S[i][j] == 1);
    }
  }

  vector dp(H + 1, vector(W + 1, 0));
  for (int i = H - 1; i >= 0; i--)
  {
    for (int j = W - 1; j >= 0; j--)
    {
      vector<int> row(H + 1, 0);
      vector<int> col(W + 1, 0);
      vector ng(H + 1, vector(W + 1, false));
      vector count(H + 1, vector(W + 1, 0));

      for (int x = H - 1; x >= i; x--)
      {
        for (int y = W - 1; y >= j; y--)
        {
          if (S[x][y] or ng[x + 1][y] or ng[x][y + 1])
          {
            ng[x][y] = true;
          }
          if (S[x][y])
          {
            count[x + 1][y + 1]++;
            row[x + 1] = 1;
            col[y + 1] = 1;
          }
        }
      }
      for (int x = 0; x < H; x++)
      {
        row[x + 1] += row[x];
      }
      for (int y = 0; y < W; y++)
      {
        col[y + 1] += col[y];
      }
      int mi = 1e9;
      for (int x = i + 1; x <= H; x++)
      {
        for (int y = j + 1; y <= W; y++)

        {
          count[x][y] += count[x - 1][y] + count[x][y - 1] - count[x - 1][y - 1];
          if (!ng[x][y])
          {
            mi = min(mi, dp[i][y] + dp[x][j] + row[x] * col[y] - count[x][y]);
          }
        }
      }
      dp[i][j] = mi;
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}
0