結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-05 10:52:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 155 ms / 2,000 ms |
| コード長 | 707 bytes |
| コンパイル時間 | 500 ms |
| コンパイル使用メモリ | 69,540 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2024-10-14 00:52:47 |
| 合計ジャッジ時間 | 4,223 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main()
| ^~~~
ソースコード
#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;
}