結果

問題 No.460 裏表ちわーわ
ユーザー kuuso1kuuso1
提出日時 2016-12-11 04:07:19
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,359 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 104,804 KB
実行使用メモリ 28,076 KB
最終ジャッジ日時 2023-08-19 11:06:10
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
28,076 KB
testcase_01 AC 56 ms
21,624 KB
testcase_02 AC 106 ms
27,864 KB
testcase_03 AC 52 ms
21,664 KB
testcase_04 AC 52 ms
19,600 KB
testcase_05 AC 82 ms
27,772 KB
testcase_06 AC 81 ms
25,824 KB
testcase_07 AC 1,802 ms
25,816 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int[] a0 = new int[H];
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(A[i][j] == 1){
					a0[i] |= (1<<j);
				}
			}
		}
		
		Min = 9999;
		fm = (1<<W)-1;
		int[] r = Enumerable.Repeat(-1,H).ToArray();
		dfs(a0,r,-1);
		
		Console.WriteLine(Min == 9999 ? "Impossible" : Min.ToString());
		
	}
	
	int Min;
	int fm;
	
	void dfs(int[] Mp, int[] route, int dep){
		if(dep == H-1){
			for(int i=0;i<H;i++) if(Mp[i] != 0) return;
			int tot = 0;
			for(int i=0;i<H;i++) tot += PopCnt(route[i]);
			Min = Math.Min(Min,tot);
			return;
		}
		
		dep++;
		for(int i=0;i<(1<<W);i++){
			int lm = 0;
			for(int j=0;j<W;j++){
				if(((i>>j) & 1) == 1){
					lm ^= j == 0 ? 3 : (7<<(j-1));
				}
			}
			lm &= fm;
			
			int[] nMp = (int[]) Mp.Clone();
			for(int j=dep-1;j<=dep+1;j++){
				if(j<0 || j>=H)continue;
				nMp[j] ^= lm;
			}
			
			if(dep-1>=0){
				if(nMp[dep-1] == 0){
					var r = (int[])route.Clone();
					r[dep] = i;
					dfs(nMp,r,dep);
				}
			}else{
				var r = (int[])route.Clone();
				r[dep] = i;
				dfs(nMp,r,dep);
			}
		}
	}
	
	
	int PopCnt(int bits){
		bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
		bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
		bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
		bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
		return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
	}
	
	int H,W;
	int[][] A;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1];
		
		A = new int[H][];
		for(int i=0;i<H;i++)A[i] = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0