using AtCoder.Internal; using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading; namespace CpLibrary.Contest { public class SolverA : SolverBase { Scanner sr; bool HasMultipleTestcases { get; } public override void Solve() { var (h, w) = sr.ReadValue(); var s = sr.ReadStringArray(h); if (s.Select(p => p.Count(q => q == '#')).Sum() == 0) { Console.WriteLine("Yes"); for (int i = 0; i < h; i++) { Console.WriteLine(s[i]); } return; } var empty = 0; for (int i = 0; i < h; i++) { bool ok = true; for (int j = 0; j < w; j++) { if (s[i][j] != '.') ok = false; } if (!ok) break; else empty = i + 1; } for (int i = empty; i < h; i++) { var c = s[i].Count(p => p == '#'); if (c == 0 || c == w) { Console.WriteLine("No"); return; } } var all = Enumerable.Repeat('#', w).Join(); var notall = Enumerable.Repeat('.', w).Join(); var a = Enumerable.Range(0, h - empty).ToArray(); do { for (int r = 0; r <= h - a[a.Length - 1] - 1; r++) { var news = new List(); for (int i = 0; i < h; i++) { if (i < r) news.Add(notall); else news.Add(all); } for (int i = 0; i < h - empty; i++) { news[h - a[i] - 1] = s[h - 1 - i]; } var block = news.Select(p => p.Count(q => q == '#')).Sum(); var mf = new AtCoder.MFGraphInt(h * w + 2); for (int i = 0; i < h; i++) { for (int j = 0; j < w - 1; j++) { if (news[i][j] == '#' && news[i][j + 1] == '#') { if ((i + j) % 2 == 0) mf.AddEdge(i * w + j, i * w + j + 1, 1); else mf.AddEdge(i * w + j + 1, i * w + j, 1); } } } for (int i = 0; i < h - 1; i++) { for (int j = 0; j < w; j++) { if (news[i][j] == '#' && news[i + 1][j] == '#') { if ((i + j) % 2 == 0) mf.AddEdge(i * w + j, (i + 1) * w + j, 1); else mf.AddEdge((i + 1) * w + j, i * w + j, 1); } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if ((i + j) % 2 == 0) mf.AddEdge(h * w, i * w + j, 1); else mf.AddEdge(i * w + j, h * w + 1, 1); } } var flow = mf.Flow(h * w, h * w + 1); if (flow * 2 == block) { Console.WriteLine("Yes"); var ans = new char[h][]; for (int i = 0; i < h; i++) { ans[i] = Enumerable.Repeat('.', w).ToArray(); } var ch = 'a'; for (int i = 0; i < mf.Edges().Length; i++) { var x = Decrypto(mf.GetEdge(i).From, h, w); var y = Decrypto(mf.GetEdge(i).To, h, w); if (x.h >= h) continue; if (y.h >= h) continue; if (mf.GetEdge(i).Flow == 1) { ans[x.h][x.w] = ch; ans[y.h][y.w] = ch; ch = Next(ch); } } for (int i = 0; i < h; i++) { Console.WriteLine(ans[i].Join()); } return; } } } while (NextCombination(a, h)); Console.WriteLine("No"); } public bool NextCombination(int[] a, int max) { a[a.Length - 1]++; var last = a.Length; for (int i = a.Length - 1; i >= 1; i--) { if (a[i] > max - (a.Length - i)) { a[i]++; a[i - 1]++; last = i; } else break; } if (a[0] >= max - a.Length) return false; for (int i = last; i < a.Length; i++) { a[i] = a[i - 1] + 1; } return true; } public (int h, int w) Decrypto(int x, int h, int w) { return (x / w, x % w); } public char Next(char x) { if (x == 'z') return 'A'; return ++x; } public SolverA(Scanner sr) => this.sr = sr; public override void Run() { var _t = 1; if (HasMultipleTestcases) _t = sr.ReadInt(); while (_t-- > 0) Solve(); } } public static partial class Util { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(uint n) { n = (n & 0x55555555) + (n >> 1 & 0x55555555); n = (n & 0x33333333) + (n >> 2 & 0x33333333); n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f); n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff); n = (n & 0x0000ffff) + (n >> 16 & 0x0000ffff); return (int)n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(int n) => PopCount((uint)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(ulong n) { n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555); n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333); n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f); n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff); n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff); n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff); return (int)n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(long n) => PopCount((ulong)n); } public static class ProgramA { private static bool StartsOnThread = true; public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var sr = new Scanner(new StreamReader(Console.OpenStandardInput())); var solver = new SolverA(sr); if (StartsOnThread) { var thread = new Thread(new ThreadStart(() => solver.Run()), 1 << 27); thread.Start(); thread.Join(); } else solver.Run(); Console.Out.Flush(); } public static void Expand() => SourceExpander.Expander.Expand(); } } #region Expanded by https://github.com/naminodarie/SourceExpander namespace AtCoder{public class MFGraphwhere TValue:struct where TOp:struct,INumOperator{static readonly TOp op=default;public MFGraph(int n){_n=n;_g=new SimpleList[n];for(int i=0;i<_g.Length;i++){_g[i]=new SimpleList();}_pos=new SimpleList<(int first,int second)>();}public int AddEdge(int from,int to,TValue cap){int m=_pos.Count;_pos.Add((from,_g[from].Count));int fromId=_g[from].Count;int toId=_g[to].Count;if(from==to)toId++;_g[from].Add(new EdgeInternal(to,toId,cap));_g[to].Add(new EdgeInternal(from,fromId,default));return m;}public Edge GetEdge(int i){var(first,second)=_pos[i];var _e=_g[first][second];var _re=_g[_e.To][_e.Rev];return new Edge(first,_e.To,op.Add(_e.Cap,_re.Cap),_re.Cap);}public Edge[]Edges(){int m=_pos.Count;var result=new Edge[m];for(int i=0;i();void Bfs(){level.AsSpan().Fill(-1);level[s]=0;que.Clear();que.Enqueue(s);while(que.Count>0){int v=que.Dequeue();foreach(var e in _g[v]){if(EqualityComparer.Default.Equals(e.Cap,default)||level[e.To]>=0)continue;level[e.To]=level[v]+1;if(e.To==t)return;que.Enqueue(e.To);}}}TValue Dfs(int v,TValue up){var lastRes=default(TValue);var stack=new Stack<(int v,TValue up,TValue res,bool childOk)>();stack.Push((v,up,default,true));DFS:while(stack.Count>0){TValue res;bool childOk;(v,up,res,childOk)=stack.Pop();if(v==s){lastRes=up;continue;}for(;iter[v]<_g[v].Count;iter[v]++,childOk=true){EdgeInternal e=_g[v][iter[v]];if(childOk){if(level[v]<=level[e.To]||EqualityComparer.Default.Equals(_g[e.To][e.Rev].Cap,default))continue;var up1=op.Subtract(up,res);var up2=_g[e.To][e.Rev].Cap;stack.Push((v,up,res,false));stack.Push((e.To,op.LessThan(up1,up2)?up1:up2,default,true));goto DFS;}else{var d=lastRes;if(op.GreaterThan(d,default)){_g[v][iter[v]].Cap=op.Add(_g[v][iter[v]].Cap,d);_g[e.To][e.Rev].Cap=op.Subtract(_g[e.To][e.Rev].Cap,d);res=op.Add(res,d);if(EqualityComparer.Default.Equals(res,up)){lastRes=res;goto DFS;}}}}level[v]=_n;lastRes=res;}return lastRes;}TValue flow=default;while(op.LessThan(flow,flowLimit)){Bfs();if(level[t]==-1)break;iter=new int[_n];var f=Dfs(t,op.Subtract(flowLimit,flow));if(EqualityComparer.Default.Equals(f,default))break;flow=op.Add(flow,f);}return flow;}public bool[]MinCut(int s){var visited=new bool[_n];var que=new Queue();que.Enqueue(s);while(que.Count>0){int p=que.Dequeue();visited[p]=true;foreach(var e in _g[p]){if(!EqualityComparer.Default.Equals(e.Cap,default)&&!visited[e.To]){visited[e.To]=true;que.Enqueue(e.To);}}}return visited;}public struct Edge:IEquatable{public int From{get;set;}public int To{get;set;}public TValue Cap{get;set;}public TValue Flow{get;set;}public Edge(int from,int to,TValue cap,TValue flow){From=from;To=to;Cap=cap;Flow=flow;}public override bool Equals(object obj)=>obj is Edge edge&&Equals(edge);public bool Equals(Edge other)=>From==other.From&&To==other.To&&EqualityComparer.Default.Equals(Cap,other.Cap)&&EqualityComparer.Default.Equals(Flow,other.Flow);public override int GetHashCode()=>HashCode.Combine(From,To,Cap,Flow);public static bool operator==(Edge left,Edge right)=>left.Equals(right);public static bool operator!=(Edge left,Edge right)=>!left.Equals(right);};internal struct EdgeInternal{public int To;public int Rev;public TValue Cap;public EdgeInternal(int to,int rev,TValue cap){To=to;Rev=rev;Cap=cap;}};internal readonly int _n;internal readonly SimpleList<(int first,int second)>_pos;internal readonly SimpleList[]_g;}} namespace AtCoder{public class MFGraphInt:MFGraph{public MFGraphInt(int n):base(n){}}public class MFGraphLong:MFGraph{public MFGraphLong(int n):base(n){}}} namespace AtCoder.Internal{public class SimpleList:IList,IReadOnlyList{private T[]data;private const int DefaultCapacity=2;public SimpleList(){data=new T[DefaultCapacity];}public SimpleList(int capacity){data=new T[Math.Max(capacity,DefaultCapacity)];}public SimpleList(IEnumerablecollection){if(collection is ICollectioncol){data=new T[col.Count];col.CopyTo(data,0);Count=col.Count;}else{data=new T[DefaultCapacity];foreach(var item in collection)Add(item);}}public SpanAsSpan()=>new Span(data,0,Count);public ref T this[int index]{[MethodImpl(MethodImplOptions.AggressiveInlining)]get{if((uint)index>=(uint)Count)ThrowIndexOutOfRangeException();return ref data[index];}}public int Count{get;private set;}public void Add(T item){if((uint)Count>=(uint)data.Length)Array.Resize(ref data,data.Length<<1);data[Count++]=item;}public void RemoveLast(){if( --Count<0)ThrowIndexOutOfRangeException();}public SimpleListReverse(){Array.Reverse(data,0,Count);return this;}public SimpleListReverse(int index,int count){Array.Reverse(data,index,count);return this;}public SimpleListSort(){Array.Sort(data,0,Count);return this;}public SimpleListSort(IComparercomparer){Array.Sort(data,0,Count,comparer);return this;}public SimpleListSort(int index,int count,IComparercomparer){Array.Sort(data,index,count,comparer);return this;}public void Clear()=>Count=0;public bool Contains(T item)=>IndexOf(item)>=0;public int IndexOf(T item)=>Array.IndexOf(data,item,0,Count);public void CopyTo(T[]array,int arrayIndex)=>Array.Copy(data,0,array,arrayIndex,Count);public T[]ToArray()=>AsSpan().ToArray();bool ICollection.IsReadOnly=>false;T IList.this[int index]{get=>data[index];set=>data[index]=value;}T IReadOnlyList.this[int index]{get=>data[index];}void IList.Insert(int index,T item)=>throw new NotSupportedException();bool ICollection.Remove(T item)=>throw new NotSupportedException();void IList.RemoveAt(int index)=>throw new NotSupportedException();IEnumerator IEnumerable.GetEnumerator()=>((IEnumerable)this).GetEnumerator();IEnumeratorIEnumerable.GetEnumerator(){for(int i=0;i.Enumerator GetEnumerator()=>AsSpan().GetEnumerator();private static void ThrowIndexOutOfRangeException()=>throw new IndexOutOfRangeException();}} namespace AtCoder{using static MethodImplOptions;public readonly struct IntOperator:INumOperator,IShiftOperator{public int MinValue=>int.MinValue;public int MaxValue=>int.MaxValue;public int MultiplyIdentity=>1;[MethodImpl(AggressiveInlining)]public int Add(int x,int y)=>x+y;[MethodImpl(AggressiveInlining)]public int Subtract(int x,int y)=>x-y;[MethodImpl(AggressiveInlining)]public int Multiply(int x,int y)=>x*y;[MethodImpl(AggressiveInlining)]public int Divide(int x,int y)=>x/y;[MethodImpl(AggressiveInlining)]public int Modulo(int x,int y)=>x%y;[MethodImpl(AggressiveInlining)]public int Minus(int x)=>-x;[MethodImpl(AggressiveInlining)]public int Increment(int x)=> ++x;[MethodImpl(AggressiveInlining)]public int Decrement(int x)=> --x;[MethodImpl(AggressiveInlining)]public bool GreaterThan(int x,int y)=>x>y;[MethodImpl(AggressiveInlining)]public bool GreaterThanOrEqual(int x,int y)=>x>=y;[MethodImpl(AggressiveInlining)]public bool LessThan(int x,int y)=>xx<=y;[MethodImpl(AggressiveInlining)]public int Compare(int x,int y)=>x.CompareTo(y);[MethodImpl(AggressiveInlining)]public int LeftShift(int x,int y)=>x<x>>y;}} namespace AtCoder{public interface IAdditionOperator{T Add(T x,T y);T Subtract(T x,T y);}public interface IMultiplicationOperator{T Multiply(T x,T y);T MultiplyIdentity{get;}}public interface IDivisionOperator:IMultiplicationOperator{T Divide(T x,T y);T Modulo(T x,T y);}public interface IUnaryNumOperator{T Minus(T x);T Increment(T x);T Decrement(T x);}public interface IArithmeticOperator:IAdditionOperator,IMultiplicationOperator,IDivisionOperator,IUnaryNumOperator{}public interface ICompareOperator:IComparer{bool GreaterThan(T x,T y);bool GreaterThanOrEqual(T x,T y);bool LessThan(T x,T y);bool LessThanOrEqual(T x,T y);}public interface INumOperator:IArithmeticOperator,ICompareOperator{T MinValue{get;}T MaxValue{get;}}public interface IShiftOperator{T LeftShift(T x,int y);T RightShift(T x,int y);}} namespace AtCoder{using static MethodImplOptions;public readonly struct LongOperator:INumOperator,IShiftOperator{public long MinValue=>long.MinValue;public long MaxValue=>long.MaxValue;public long MultiplyIdentity=>1L;[MethodImpl(AggressiveInlining)]public long Add(long x,long y)=>x+y;[MethodImpl(AggressiveInlining)]public long Subtract(long x,long y)=>x-y;[MethodImpl(AggressiveInlining)]public long Multiply(long x,long y)=>x*y;[MethodImpl(AggressiveInlining)]public long Divide(long x,long y)=>x/y;[MethodImpl(AggressiveInlining)]public long Modulo(long x,long y)=>x%y;[MethodImpl(AggressiveInlining)]public long Minus(long x)=>-x;[MethodImpl(AggressiveInlining)]public long Increment(long x)=> ++x;[MethodImpl(AggressiveInlining)]public long Decrement(long x)=> --x;[MethodImpl(AggressiveInlining)]public bool GreaterThan(long x,long y)=>x>y;[MethodImpl(AggressiveInlining)]public bool GreaterThanOrEqual(long x,long y)=>x>=y;[MethodImpl(AggressiveInlining)]public bool LessThan(long x,long y)=>xx<=y;[MethodImpl(AggressiveInlining)]public int Compare(long x,long y)=>x.CompareTo(y);[MethodImpl(AggressiveInlining)]public long LeftShift(long x,int y)=>x<x>>y;}} namespace CpLibrary { public static class Extention { public static string Join(this IEnumerable x, string separator = "") => string.Join(separator, x); public static string Join(this IEnumerable x, char separator) => string.Join(separator, x); public static int UpperBound(this IList list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer.Default); public static int LowerBound(this IList list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer.Default); public static int BinarySearch(this IList list, T value, bool isUpperBound, int index, int length, Comparer comparer) { var ng = index - 1; var ok = index + length; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var res = comparer.Compare(list[mid], value); if (res < 0 || (isUpperBound && res == 0)) ng = mid; else ok = mid; } return ok; } public static bool Chmax(ref this T a, T b) where T : struct, IComparable { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin(ref this T a, T b) where T : struct, IComparable { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } } namespace CpLibrary { public class Scanner { public StreamReader sr { get; private set; } string[] str; int index; char[] separators; public Scanner(StreamReader sr, char[] separators) { this.sr = sr; this.separators = separators; str = new string[0]; index = 0; } public Scanner(StreamReader sr): this(sr, new char[]{' '}) { } public Scanner(): this(new StreamReader(Console.OpenStandardInput()), new char[]{' '}) { } public string Read() { if (index < str.Length) return str[index++]; string s; do s = sr.ReadLine(); while (s == ""); str = s.Split(separators, StringSplitOptions.RemoveEmptyEntries); index = 0; return str[index++]; } public string ReadString() => Read(); public string[] ReadStringArray(int n) { var arr = new string[n]; for (int i = 0; i < n; i++) { arr[i] = ReadString(); } return arr; } public int ReadInt() => int.Parse(ReadString()); public int[] ReadIntArray(int n) => ReadValueArray(n); public long ReadLong() => long.Parse(ReadString()); public long[] ReadLongArray(int n) => ReadValueArray(n); public double ReadDouble() => double.Parse(ReadString()); public double[] ReadDoubleArray(int n) => ReadValueArray(n); public BigInteger ReadBigInteger() => BigInteger.Parse(ReadString()); public T1 ReadValue() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public T1[] ReadValueArray(int n) { var arr = new T1[n]; for (int i = 0; i < n; i++) { arr[i] = ReadValue(); } return arr; } public (T1, T2) ReadValue() => (ReadValue(), ReadValue()); public (T1, T2, T3) ReadValue() => (ReadValue(), ReadValue(), ReadValue()); public (T1, T2, T3, T4) ReadValue() => (ReadValue(), ReadValue(), ReadValue(), ReadValue()); public (T1, T2, T3, T4, T5) ReadValue() => (ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue()); public (T1, T2, T3, T4, T5, T6) ReadValue() => (ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue()); public (T1, T2, T3, T4, T5, T6, T7) ReadValue() => (ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue(), ReadValue()); public (T1[], T2[]) ReadValueArray(int n) { var(v1, v2) = (new T1[n], new T2[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i]) = ReadValue(); } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray(int n) { var(v1, v2, v3) = (new T1[n], new T2[n], new T3[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i]) = ReadValue(); } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray(int n) { var(v1, v2, v3, v4) = (new T1[n], new T2[n], new T3[n], new T4[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i]) = ReadValue(); } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray(int n) { var(v1, v2, v3, v4, v5) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i]) = ReadValue(); } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray(int n) { var(v1, v2, v3, v4, v5, v6) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i]) = ReadValue(); } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray(int n) { var(v1, v2, v3, v4, v5, v6, v7) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n], new T7[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i], v7[i]) = ReadValue(); } return (v1, v2, v3, v4, v5, v6, v7); } } } namespace CpLibrary { public interface ISolver { public void Solve(); public void Run(); } public abstract class SolverBase : ISolver { public abstract void Solve(); public abstract void Run(); public bool YesNo(bool condition) { Console.WriteLine(condition ? "Yes" : "No"); return condition; } public bool YESNO(bool condition) { Console.WriteLine(condition ? "YES" : "NO"); return condition; } public bool yesno(bool condition) { Console.WriteLine(condition ? "yes" : "no"); return condition; } } } namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}} #endregion Expanded by https://github.com/naminodarie/SourceExpander