結果

問題 No.2473 Fraises dans une boîte
ユーザー lgswdnlgswdn
提出日時 2024-03-09 17:01:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 4,000 ms
コード長 2,056 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 204,236 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-09 17:01:50
合計ジャッジ時間 9,503 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 8 ms
6,676 KB
testcase_41 AC 8 ms
6,676 KB
testcase_42 AC 3 ms
6,676 KB
testcase_43 AC 43 ms
6,676 KB
testcase_44 AC 44 ms
6,676 KB
testcase_45 AC 10 ms
6,676 KB
testcase_46 AC 107 ms
6,676 KB
testcase_47 AC 99 ms
6,676 KB
testcase_48 AC 98 ms
6,676 KB
testcase_49 AC 174 ms
6,676 KB
testcase_50 AC 58 ms
6,676 KB
testcase_51 AC 169 ms
6,676 KB
testcase_52 AC 171 ms
6,676 KB
testcase_53 AC 174 ms
6,676 KB
testcase_54 AC 136 ms
6,676 KB
testcase_55 AC 173 ms
6,676 KB
testcase_56 AC 68 ms
6,676 KB
testcase_57 AC 137 ms
6,676 KB
testcase_58 AC 66 ms
6,676 KB
testcase_59 AC 38 ms
6,676 KB
testcase_60 AC 174 ms
6,676 KB
testcase_61 AC 106 ms
6,676 KB
testcase_62 AC 143 ms
6,676 KB
testcase_63 AC 71 ms
6,676 KB
testcase_64 AC 56 ms
6,676 KB
testcase_65 AC 172 ms
6,676 KB
testcase_66 AC 46 ms
6,676 KB
testcase_67 AC 4 ms
6,676 KB
testcase_68 AC 165 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Shirasu Azusa 2024.03
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=305;
int n,m,a[N][N],f[N][N],s[N][N];

int sum(int u,int d,int l,int r) {
  if(u>d||l>r) return 0;
  else return s[d][r]-s[u-1][r]-s[d][l-1]+s[u-1][l-1];
}

signed main() {
  n=read(), m=read();
  rep(i,1,n) rep(j,1,m) a[i][j]=read();
  rep(i,1,n) rep(j,1,m) s[i][j]=s[i-1][j]+a[i][j];
  rep(i,1,n) rep(j,1,m) s[i][j]=s[i][j]+s[i][j-1];
  per(i,n,1) per(j,m,1) {
    static int cx[N],cy[N]; cx[i-1]=cy[j-1]=0;
    if(!sum(i,n,j,m)) continue;
    rep(k,i,n) cx[k]=cx[k-1]+!!sum(k,k,j,m);
    rep(k,j,m) cy[k]=cy[k-1]+!!sum(i,n,k,k);
    f[i][j]=(n-i+1)*(m-j+1);
    for(int x=i,y=m;x<=n;x++) {
      while(y>=j&&!sum(x+1,n,y+1,m)) y--; y++;
      chmin(f[i][j],f[x+1][j]+f[i][y+1]+cx[x]*cy[y]-sum(i,x,j,y));
    }
  }
  printf("%lld\n",f[1][1]);
  return 0;
}
0