SRM 494 Div1-Easy&Div2-Medium "Painting"
本番では最小の幅を求めて失敗した問題。
5重ループで解いてみた。
実装(VB.NET)
Imports Microsoft.VisualBasic Imports System Imports System.Collections Imports System.Text Public Class Painting Dim Map(50,50) As Byte Dim Test(50,50) As Byte Dim W As Integer,H As Integer Public Sub ClearTest() For i as Integer=0 To 50 For j as Integer=0 To 50 Test(i,j)=0 Next j Next i End Sub Public Function largestBrush(ByVal picture As String()) As Integer Dim i As Integer,j As Integer,s As Integer,k As Integer,l As Integer,Check As Boolean W=Len(picture(0)) H=UBound(picture)+1 For i=0 To H-1 For j=0 To W-1 If Mid(picture(i),j+1,1)="B" Then Map(j,i)=1 End If Next j Next i For s=Math.Min(H,W) To 2 Step -1 ClearTest() For i=0 To w-s For j=0 To h-s Check=True For k=0 To s-1 For l=0 To S-1 If Map(k+i,j+l)=0 Then Check=False Next l Next k If Check=True Then For k=0 To s-1 For l=0 To S-1 Test(k+i,l+j)=1 Next l Next k End If Next j Next i Check=True For i=0 To W-1 For j=0 To H-1 If Map(i,j)<>Test(i,j) Then Check=False Next j Next i If Check=True Then Return s Next s Return 1 End Function End Class