結果

問題 No.421 しろくろチョコレート
ユーザー kuuso1kuuso1
提出日時 2016-09-10 00:33:28
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,371 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 107,220 KB
実行使用メモリ 29,296 KB
最終ジャッジ日時 2023-08-10 22:48:28
合計ジャッジ時間 11,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
29,296 KB
testcase_01 AC 68 ms
20,664 KB
testcase_02 AC 62 ms
20,708 KB
testcase_03 AC 59 ms
20,784 KB
testcase_04 AC 61 ms
20,696 KB
testcase_05 AC 59 ms
22,788 KB
testcase_06 AC 60 ms
20,716 KB
testcase_07 AC 62 ms
20,620 KB
testcase_08 AC 62 ms
20,648 KB
testcase_09 AC 60 ms
20,648 KB
testcase_10 AC 60 ms
18,680 KB
testcase_11 AC 64 ms
20,800 KB
testcase_12 AC 60 ms
20,776 KB
testcase_13 AC 59 ms
20,700 KB
testcase_14 AC 60 ms
20,752 KB
testcase_15 AC 57 ms
20,576 KB
testcase_16 AC 81 ms
20,904 KB
testcase_17 AC 76 ms
20,728 KB
testcase_18 AC 76 ms
22,756 KB
testcase_19 AC 59 ms
20,800 KB
testcase_20 AC 69 ms
22,688 KB
testcase_21 AC 72 ms
22,804 KB
testcase_22 AC 64 ms
20,660 KB
testcase_23 AC 58 ms
22,808 KB
testcase_24 AC 59 ms
20,804 KB
testcase_25 AC 59 ms
20,688 KB
testcase_26 AC 59 ms
20,768 KB
testcase_27 AC 59 ms
22,756 KB
testcase_28 AC 66 ms
20,672 KB
testcase_29 AC 63 ms
22,816 KB
testcase_30 AC 63 ms
20,792 KB
testcase_31 AC 518 ms
18,608 KB
testcase_32 AC 64 ms
20,732 KB
testcase_33 AC 66 ms
20,716 KB
testcase_34 AC 59 ms
20,808 KB
testcase_35 AC 62 ms
22,640 KB
testcase_36 AC 64 ms
20,752 KB
testcase_37 AC 76 ms
22,696 KB
testcase_38 AC 85 ms
20,752 KB
testcase_39 AC 62 ms
20,764 KB
testcase_40 AC 100 ms
20,888 KB
testcase_41 AC 60 ms
20,744 KB
testcase_42 AC 59 ms
18,700 KB
testcase_43 AC 64 ms
20,752 KB
testcase_44 AC 156 ms
22,808 KB
testcase_45 AC 60 ms
22,788 KB
testcase_46 AC 60 ms
20,728 KB
testcase_47 AC 65 ms
22,804 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