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