結果

問題 No.460 裏表ちわーわ
ユーザー furafura
提出日時 2020-08-07 01:14:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 945 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 204,348 KB
実行使用メモリ 5,948 KB
最終ジャッジ日時 2023-10-22 04:10:24
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 5 ms
5,852 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 5 ms
5,852 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 6 ms
5,852 KB
testcase_14 AC 5 ms
5,852 KB
testcase_15 AC 5 ms
5,852 KB
testcase_16 WA -
testcase_17 AC 5 ms
5,852 KB
testcase_18 AC 5 ms
5,852 KB
testcase_19 AC 6 ms
5,852 KB
testcase_20 WA -
testcase_21 AC 5 ms
5,852 KB
testcase_22 AC 5 ms
5,852 KB
testcase_23 AC 5 ms
5,852 KB
testcase_24 AC 5 ms
5,852 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 RE -
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0