結果

問題 No.460 裏表ちわーわ
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 10:52:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 70,092 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 02:12:13
合計ジャッジ時間 4,753 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int H,W;
int A[9];
int dp[9][1<<16];
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;
	for(int i=0;i<H;i++)for(int j=0;j<1<<2*W;j++)
	{
		for(int k=0;k<1<<W;k++)
		{
			int t=(k^k>>1^k<<1)&(1<<W)-1;
			if((j>>W)==t)
			{
				int nx=(j&(1<<W)-1^t)<<W|A[i+1]^t;
				dp[i+1][nx]=min(dp[i+1][nx],dp[i][j]+__builtin_popcount(k));
			}
		}
	}
	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