結果

問題 No.460 裏表ちわーわ
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 11:01:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 69,612 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-04-22 02:12:27
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 4 ms
5,888 KB
testcase_06 AC 4 ms
5,888 KB
testcase_07 AC 4 ms
5,888 KB
testcase_08 AC 5 ms
5,888 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,760 KB
testcase_11 AC 5 ms
5,760 KB
testcase_12 AC 4 ms
5,888 KB
testcase_13 AC 4 ms
5,888 KB
testcase_14 AC 5 ms
5,888 KB
testcase_15 AC 5 ms
5,888 KB
testcase_16 AC 4 ms
5,888 KB
testcase_17 AC 5 ms
5,888 KB
testcase_18 AC 4 ms
5,888 KB
testcase_19 AC 5 ms
5,888 KB
testcase_20 AC 4 ms
5,888 KB
testcase_21 AC 4 ms
5,888 KB
testcase_22 AC 5 ms
5,760 KB
testcase_23 AC 5 ms
5,888 KB
testcase_24 AC 5 ms
5,888 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int H,W;
int A[9];
int dp[9][1<<16];
int cost[1<<8];
main()
{
	cin>>H>>W;
	for(int i=0;i<H;i++)
	{
		int t=0;
		for(int j=0;j<W;j++)
		{
			int a;cin>>a;
			t=t*2+a;
		}
		A[i]=t;
	}
	for(int i=0;i<=H;i++)for(int j=0;j<1<<2*W;j++)dp[i][j]=1e9;
	for(int i=0;i<1<<W;i++)dp[0][i<<W|A[0]]=0,cost[i]=1e9;
	for(int i=0;i<1<<W;i++)
	{
		int t=(i^i>>1^i<<1)&(1<<W)-1;
		cost[t]=min(cost[t],__builtin_popcount(i));
	}
	for(int i=0;i<H;i++)for(int j=0;j<1<<2*W;j++)
	{
		int t=j>>W;
		int nx=(j&(1<<W)-1^t)<<W|A[i+1]^t;
		dp[i+1][nx]=min(dp[i+1][nx],dp[i][j]+cost[t]);
	}
	int ans=1e9;
	for(int j=0;j<1<<W;j++)ans=min(ans,dp[H][j]);
	if(ans<1e9)cout<<ans<<endl;
	else cout<<"Impossible"<<endl;
}
0