結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-07 01:14:01 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 945 bytes |
| コンパイル時間 | 7,252 ms |
| コンパイル使用メモリ | 255,532 KB |
| 最終ジャッジ日時 | 2025-01-12 15:35:21 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 7 RE * 3 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
inline int popcount(unsigned int x){
x-=(x>>1)&0x55555555;
x=(x&0x33333333)+((x>>2)&0x33333333);
return ((x+(x>>4)&0x0f0f0f0f)*0x01010101)>>24;
}
int main(){
int h,w; scanf("%d%d",&h,&w);
int B[8]={};
rep(i,h) rep(j,w) {
int a; scanf("%d",&a);
B[i]|=a<<j;
}
vector<int> cost(1<<w,INF);
rep(S,1<<w){
int pttn={};
rep(j,w) if(S>>j&1) {
if(j> 0 ) pttn^=1<<(j-1);
pttn^=1<<j;
if(j<w-1) pttn^=1<<(j+1);
}
cost[pttn]=min(cost[pttn],popcount(S));
}
static int dp[8][1<<8][1<<8];
rep(i,h) rep(S,1<<w) rep(T,1<<w) dp[i][S][T]=INF;
rep(S,1<<w) dp[0][B[0]^S][B[1]^S]=cost[S];
for(int i=1;i<h-1;i++){
rep(S,1<<w) rep(T,1<<w) {
dp[i][T^S][B[i+1]^S]=min(dp[i][T^S][B[i+1]^S],dp[i-1][S][T]+cost[S]);
}
}
int ans=INF;
rep(S,1<<w) ans=min(ans,dp[h-2][S][S]+cost[S]);
printf("%d\n",ans);
return 0;
}