Created
December 24, 2015 17:18
-
-
Save knuu/e1e1df71c0ebf675536e to your computer and use it in GitHub Desktop.
SRM663 div.1 300 ABBADiv1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ABBADiv1: | |
def canObtain(self, initial, target): | |
def dfs(s): | |
if len(s) == len(target): | |
return s == target | |
if s not in target and s not in rev_target: | |
return False | |
return dfs(s + 'A') or dfs((s + 'B')[::-1]) | |
rev_target = target[::-1] | |
return "Possible" if dfs(initial) else "Impossible" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment