結果

問題 No.421 しろくろチョコレート
ユーザー kuuso1kuuso1
提出日時 2016-09-10 00:33:28
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,371 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 114,436 KB
実行使用メモリ 29,972 KB
最終ジャッジ日時 2024-04-28 15:44:25
合計ジャッジ時間 8,942 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
29,004 KB
testcase_01 AC 30 ms
23,900 KB
testcase_02 AC 26 ms
24,128 KB
testcase_03 AC 24 ms
23,928 KB
testcase_04 AC 24 ms
24,184 KB
testcase_05 AC 25 ms
26,152 KB
testcase_06 AC 24 ms
23,804 KB
testcase_07 AC 27 ms
24,240 KB
testcase_08 AC 25 ms
25,840 KB
testcase_09 AC 26 ms
25,844 KB
testcase_10 AC 25 ms
23,968 KB
testcase_11 AC 28 ms
24,064 KB
testcase_12 AC 25 ms
26,016 KB
testcase_13 AC 24 ms
21,940 KB
testcase_14 AC 24 ms
24,188 KB
testcase_15 AC 23 ms
23,928 KB
testcase_16 AC 44 ms
24,212 KB
testcase_17 AC 39 ms
24,220 KB
testcase_18 AC 40 ms
22,172 KB
testcase_19 AC 25 ms
24,056 KB
testcase_20 AC 33 ms
24,236 KB
testcase_21 AC 35 ms
23,956 KB
testcase_22 AC 26 ms
22,196 KB
testcase_23 AC 23 ms
23,984 KB
testcase_24 AC 23 ms
23,856 KB
testcase_25 AC 24 ms
24,096 KB
testcase_26 AC 24 ms
25,888 KB
testcase_27 AC 24 ms
26,148 KB
testcase_28 AC 29 ms
26,020 KB
testcase_29 AC 27 ms
22,196 KB
testcase_30 AC 27 ms
26,020 KB
testcase_31 AC 455 ms
24,220 KB
testcase_32 AC 30 ms
23,896 KB
testcase_33 AC 30 ms
28,112 KB
testcase_34 AC 25 ms
24,240 KB
testcase_35 AC 26 ms
23,796 KB
testcase_36 AC 27 ms
24,064 KB
testcase_37 AC 38 ms
26,000 KB
testcase_38 AC 46 ms
23,824 KB
testcase_39 AC 26 ms
24,116 KB
testcase_40 AC 57 ms
24,028 KB
testcase_41 AC 26 ms
23,964 KB
testcase_42 AC 25 ms
23,976 KB
testcase_43 AC 28 ms
24,188 KB
testcase_44 AC 127 ms
22,068 KB
testcase_45 AC 25 ms
23,856 KB
testcase_46 AC 27 ms
25,972 KB
testcase_47 AC 31 ms
24,240 KB
testcase_48 TLE -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 V = N*M+2;
		int src = N*M;
		int sink = src+1;
		var Gr = new MaxFlow_Dinic();
		Gr.Init(V);
		int b = 0;
		int w = 0;
		
		int[] dx = new int[]{1,0,-1,0};
		int[] dy = new int[]{0,-1,0,1};
		Func<int,int,bool> InRange = (y,x) =>{
			return 0<= x && x < M && 0<= y && y < N;
		};
		
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++){
				if(S[i][j] == 'b'){
					b++;
					Gr.AddEdge(src,i*M+j,1);
					for(int t=0;t<4;t++){
						int nx = j + dx[t];
						int ny = i + dy[t];
						if(!InRange(ny,nx))continue;
						if(S[ny][nx] == 'w'){
							Gr.AddEdge(i*M+j,ny*M+nx,1);
						}
					}
				}
				if(S[i][j] == 'w'){
					w++;
					Gr.AddEdge(i*M+j,sink,1);
				}
			}
		}
		int bw = Gr.MaxFlow(src,sink);
		int ans = bw * 100;
		b -= bw;
		w -= bw;
		int bws = Math.Min(b,w);
		ans += bws * 10;
		b -= bws;
		w -= bws;
		ans += b;
		ans += w;
		
		Console.WriteLine(ans);
		
		
		
		
	}
	int N,M;
	String[] S;
	public Sol(){
		var d = ria();
		N = d[0];
		M = d[1];
		S = new String[N];
		for(int i=0;i<N;i++)S[i] = rs();
	}

	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));}
}


class MaxFlow_Dinic{
	// arihon is god
	class Edge {
		public int To,Cap,Rev;
		public Edge(int to = 0,int cap = 0,int rev = 0){
			To = to;
			Cap = cap;
			Rev = rev;
		}
	}
	
	List<Edge>[] G;
	int[] Level;
	int[] Iter;
	
	static int Inf = (int) 1e9;
	public int N;
	public void Init(int n){
		N = n;
		G = new List<Edge>[N];
		for(int i=0;i<N;i++) G[i] = new List<Edge>();
		Level = new int[N];
		Iter = new int[N];
	}
	
	
	public void AddEdge(int from, int to, int cap){
		G[from].Add(new Edge(to,cap,G[to].Count));
		G[to].Add(new Edge(from,0,G[from].Count-1));
	}
	
	void bfs(int s){
		for(int j=0;j<G.Length;j++)Level[j] = -1;
		var Q = new Queue<int>();
		Level[s] = 0;
		Q.Enqueue(s);
		
		while(Q.Count>0){
			var v = Q.Dequeue();
			foreach(var e in G[v]){
//Console.WriteLine(e.Cap +" "+Level[e.To]);
				if(e.Cap > 0 && Level[e.To] < 0){
					Level[e.To] = Level[v] + 1;
					Q.Enqueue(e.To);
				}
			}
		}
	}
	
	int dfs(int v,int t,int f){
		if(v == t) return f;
		for(int i = Iter[v]; i<G[v].Count;i++){
			var e = G[v][i];
			if(e.Cap > 0 && Level[v] < Level[e.To]){
				int d = dfs(e.To,t,Math.Min(f,e.Cap));
				if(d > 0){
					e.Cap -= d;
					G[e.To][e.Rev].Cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	public int MaxFlow(int s,int t){
		int flow = 0;
		while(true){
			bfs(s);
//Console.WriteLine(Level[t]);
			if(Level[t] < 0) return flow;
			Iter = new int[N];
			
			int f;
			while( ( f = dfs(s,t,Inf)) > 0){
				flow += f;
			}
		}
	}
	
	
}
0