BottomCoder SRM 360 Div2

結果
Easy(250) 243.98
Medium(500) Compiled
Hard(1000) Compiled


Easy
実装するだけ

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Text
Imports System.Math
Imports Weight=System.Int32
Public Class AzimuthMonitoring
'Right+
	Public Function getAzimuth(ByVal instructions As String()) As Integer
		Dim i As Integer,j As Integer
		For i=0 To Ubound(instructions)
			If instructions(i)="HALT" Then
				Exit For
			ElseIf instructions(i)="TURN AROUND" Then
				getAzimuth+=180
			ElseIf instructions(i)="RIGHT" Then
				getAzimuth+=90
			ElseIf instructions(i)="LEFT" Then
				getAzimuth-=90
<span style="font-weight:bold;"></span>			Else
				Dim Strs() As String=Split(instructions(i)," ")
				If Strs(0)="LEFT" Then
					getAzimuth-=Val(Strs(1))
				Else
					getAzimuth+=Val(Strs(1))
				End If
			End If
		Next
		getAzimuth=getAzimuth Mod 360
		getAzimuth=(getAzimuth+720) Mod 360
	End Function

End Class

Normal
未だに良く分かっていない

Hard
10^iの値をメモ化すればTLEを避けられた…。

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Text
Imports System.Math
Imports Weight = System.Int32
Public Class TakeSubstringGame
    Public Shared V(1000000, 1) As Integer 'Aが確実に勝利=Bが確実に敗北
    Public Shared Saizen(1000000) As Integer
    Public Shared TTT(100) As Integer
    Public Shared Function Solve(ByVal n As Integer, ByVal t As Integer) As Integer
        Dim i As Integer, j As Integer
        If (V(n, t) >= -1) Then Return V(n, t)
        Dim l As Integer = Int(Log10(n)) + 1, tt As Integer
        Dim res As Integer = 0
        If t = 0 Then
            For q As Integer = 0 To l - 1
                For r As Integer = 1 To l - q
                    tt = (n \ (TTT(q))) Mod (TTT(r))
                    If tt = 0 Or tt = n Then Continue For
                    If Solve(n - tt, 1 - t) = 1 Then
                        V(n, t) = 1
                        Saizen(n) = Min(Saizen(n), tt)
                        res = 1
                    End If
                Next
            Next
            If res Then Return 1
            V(n, t) = 0
            Return 0
        Else
            For q As Integer = 0 To l - 1
                For r As Integer = 1 To l - q
                    tt = (n \ TTT(q)) Mod TTT(r)
                    If tt = 0 Or tt = n Then Continue For
                    If Solve(n - tt, 1 - t) = 0 Then
                        V(n, t) = 0
                        Return 0
                    End If
                Next
            Next
            V(n, t) = 1
            Return 1
        End If
    End Function
    Public Function winningMove(ByVal n As Integer) As Integer
        Dim i As Integer
        For i = 0 To (1000000)
            V(i, 0) = -2
            V(i, 1) = -2
            Saizen(i) = 999999999
        Next
        For i = 0 To 9
            TTT(i) = 10 ^ i
        Next i
        If Solve(n, 0) = 0 Then Return -1
        Return Saizen(n)
    End Function
End Class