Problem: Snuke, who loves animals, built a zoo.  There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.  There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.  Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species.  More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise.  Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.

Submission attempts (in order):
N = int(input())
s = input()

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
         
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W" 
    if tmp != SW[i]:
      break
    
    ans = "".join(SW)
        
print(ans)


N = int(input())
s = input()

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
          
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
          
  if SW[0] == items[0] and SW[1] == items[1]:
    ans = "".join(SW)
        
print(ans)


N = int(input())
s = input()

ans = -1

candidate = [["S", "S"], ["S", "W"], ["W", "S"], ["W", "W"]]

for items in candidate:
  SW = [""] * N
  SW[0] = items[0]
  SW[1] = items[1]
    
  for i in range(1, N-1):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          SW[i+1] = "W"
        else:
          SW[i+1] = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          SW[i+1] = "S"
        else:
          SW[i+1] = "W"
  
  flag = True
  
  for i in range(-1, 0):
    if s[i] == "o":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
    if s[i] == "x":
      if SW[i] == "S":
        if SW[i-1] == "S":
          tmp = "W"
        else:
          tmp = "S"
      if SW[i] == "W":
        if SW[i-1] == "S":
          tmp = "S"
        else:
          tmp = "W" 
    if tmp != SW[i]:
      flag = False
    
  if flag:
    ans = "".join(SW)
        
print(ans)


n = int(input())
s = input()
ans = ""
def next_animal(pre,now,letter):
    if pre == "S" and now == "S" and letter == "o":
        return "S"
    if pre == "S" and now == "S" and letter == "x":
        return "W"
    if pre == "S" and now == "W" and letter == "o":
        return "W"
    if pre == "S" and now == "W" and letter == "x":
        return "S"
    if pre == "W" and now == "S" and letter == "o":
        return "W"
    if pre == "W" and now == "S" and letter == "x":
        return "S"
    if pre == "W" and now == "W" and letter == "o":
        return "S"
    if pre == "W" and now == "W" and letter == "x":
        return "W"

for case in range(4):
    if case == 0:
        ans = "SS"
    if case == 1:
        ans = "SW"
    if case == 2:
        ans = "WS"
    if case == 3:
        ans = "WW"
    for i in range(1,n-1):
        next = next_animal(ans[-1],ans[-2],s[i])
        ans += next
    if ans[-1] == next_animal(ans[1],ans[0],s[0]) and ans[0] == next_animal(ans[-2],ans[-1],s[-1]):
        print(ans)
        exit()

print(-1)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted