Problem:


Score : 500 points

Problem Statement

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.

Constraints

3 ≤ N ≤ 10^{5}

s is a string of length N consisting of o and x.

Input

The input is given from Standard Input in the following format:

N
s

Output

If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.

t is a string of length N consisting of S and W.

If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

Sample Input 1

6
ooxoox

Sample Output 1

SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2

3
oox

Sample Output 2

-1

Print -1 if there is no valid assignment of species.

Sample Input 3

10
oxooxoxoox

Sample Output 3

SSWWSSSWWS



Sample input:
6
ooxoox


Sample output:
SSSWWS

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

pat = ["WW","WS","SW","SS"]

for j in pat:
    now = j
    flag = True
    for i in range(1,n):
        if now[i] == "S" and now[i-1] == "S":
            if s[i] == "o":
                now += "S"
            else:
                now += "W"
        elif now[i] == "S" and now[i-1] == "W":
            if s[i] == "o":
                now += "W"
            else:
                now += "S"
        elif now[i] == "W" and now[i-1] == "S":
            if s[i] == "o":
                now += "W"
            else:
                now += "S"
        else:
            if s[i] == "o":
                now += "S"
            else:
                now += "W"
    if now[-1] != now[0]:
        flag = False
    ss = s[-1]+ s + s[0]
    now = now[-1] + now
    for k in range(1,n+1):
        if ss[k] == "o" and now[k] == "S":
            if now[k-1] != now[k+1]:
                flag = False
                break
        elif ss[k] == "x" and now[k] == "S":
            if now[k-1] == now[k+1]:
                flag = False
                break
        elif ss[k] == "o" and now[k] == "W":
            if now[k-1] == now[k+1]:
                flag = False
                break
        else:
            if now[k-1] != now[k+1]:
                flag = False
                break
    if flag:
        print(now[1:-1])
        exit()
print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def check_no_contradict(n, new_s, pattern):
        animals = [None] * (n + 1)
        animals[0], animals[1] = pattern
        for i in range(1, n):
            animals[i+1] = animals[i-1] if (animals[i] and new_s[i] == 'o') or (not animals[i] and new_s[i] == 'x') else not animals[i-1]
        if animals[0] == animals[n]:
            return animals[:n]
        else:
            return []


    
    n = ii()
    s = input()
    new_s = s + s[0]    # [0]...[n-1] が本来の証言たち
    for pattern in product([True, False], repeat=2):
        result = check_no_contradict(n, new_s, pattern)
        if result:
            # print(pattern)
            # print(result)
            print(''.join(list(map(lambda x: 'S' if x else 'W', result))))
            exit()
    print(-1)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s += s[0]
d = {'S':'W', 'W':'S'}
flag = True
for sw in ['SS', 'WW', 'SW', 'WS']:
    l = sw
    for i in range(1, n):
        if l[i] == 'S' and s[i] == 'o' or l[i] == 'W' and s[i] == 'x':
            l += l[i-1]
        else:
            l += d[l[i-1]]
    if l[0] == l[-1]:
        print(l[:-1])
        flag = False
        break
if flag:
    print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
t = []
for i in range(n):
    if s[i] == 'o':
        t.append(0)
    else:
        t.append(1)
for zero,one in itertools.product(range(2),repeat=2):
    res = [None] * n
    res[0] = zero; res[1] = one
    for i in range(2,n):
        if res[i-1] ^ t[i-1] == 0:
            res[i] = res[i-2]
        else:
            res[i] = res[i-2]^1
    if (res[0] ^ res[-2]) == (res[-1] ^ t[-1]):
        ans = []
        for i in range(n):
            ans.append('W' if res[i] else 'S')
        print(''.join(ans))
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()

def rev(x):
    if x=="S":
        return "W"
    else:
        return "S"

def wolfsheep(xy):
    global n,s
    result=[xy[0],xy[1]]

    for i in range(1,n):
        if result[i]=="S":
            if s[i]=="o":
                result.append(result[i-1])
            else:
                result.append(rev(result[i-1]))
        else:
            if s[i]=="o":
                result.append(rev(result[i-1]))
            else:
                result.append(result[i-1])

    if result[0]==result[n]:
        return result
    else:
        return 0

#SWパターン
tmp= wolfsheep("SW")
if tmp!=0:
    print("".join(tmp[:-1]))
    exit()

#SSパターン
tmp= wolfsheep("SS")
if tmp!=0:
    print("".join(tmp[:-1]))
    exit()
#WWパターン
tmp= wolfsheep("WW")
if tmp!=0:
    print("".join(tmp[:-1]))
    exit()
#WSパターン
tmp= wolfsheep("WS")
if tmp!=0:
    print("".join(tmp[:-1]))
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()

def rev(x):
    if x=="S":
        return "W"
    else:
        return "S"

def wolfsheep(xy):
    global n,s
    result=[xy[0],xy[1]]

    for i in range(1,n):
        if result[i]=="S":
            if s[i]=="o":
                result.append(result[i-1])
            else:
                result.append(rev(result[i-1]))
        else:
            if s[i]=="o":
                result.append(rev(result[i-1]))
            else:
                result.append(result[i-1])

    if result[0]==result[n]:
        return result
    else:
        return 0

#SWパターン
tmp= wolfsheep("SW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

#SSパターン
tmp= wolfsheep("SS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WWパターン
tmp= wolfsheep("WW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WSパターン
tmp= wolfsheep("WS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    L = ["S", "W"]

    for first in L:
        for second in L:
            res = ["" for _ in range(n)]
            res[0] = first
            res[1] = second
            for i in range(1, n - 1):
                if s[i] == "o":
                    if res[i] == "S" and res[i - 1] == "S":
                        res[i + 1] = "S"
                    elif res[i] == "S" and res[i - 1] == "W":
                        res[i + 1] = "W"
                    elif res[i] == "W" and res[i - 1] == "W":
                        res[i + 1] = "S"
                    else:
                        res[i + 1] = "W"
                else:
                    if res[i] == "S" and res[i - 1] == "S":
                        res[i + 1] = "W"
                    elif res[i] == "S" and res[i - 1] == "W":
                        res[i + 1] = "S"
                    elif res[i] == "W" and res[i - 1] == "W":
                        res[i + 1] = "W"
                    else:
                        res[i + 1] = "S"
            if s[-1] == "o":
                if res[-1] == "S":
                    if res[-2] == res[0]:
                        print("".join(res))
                        exit()
                if res[-1] == "W":
                    if res[-2] != res[0]:
                        print("".join(res))
                        exit()
            else:
                if res[-1] == "S":
                    if res[-2] != res[0]:
                        print("".join(res))
                        exit()
                if res[-1] == "W":
                    if res[-2] == res[0]:
                        print("".join(res))
                        exit()
    else:
        print(-1)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())

s = input()


def fnc(x1, x2):
    pre = x1
    curr = x2
    ans = [x1]
    for i in range(1, N):
        if curr == 1:  # 羊
            if s[i] == 'o':
                nv = pre
            else:
                nv = (pre + 1) % 2
        else:  # 狼
            if s[i] == 'x':
                nv = pre
            else:
                nv = (pre + 1) % 2
        pre = curr
        curr = nv
        ans.append(pre)

    if curr == x1:
        return ans
    else:
        return None


def solve():
    for i in [0,1]:
        for j in [0,1]:
            ans = fnc(i, j)
            if ans:
                return ans
    return None


if __name__ == '__main__':
    ans = solve()
    if not ans:
        print(-1)
        exit()

    for a in ans:
        print('S' if a else 'W', end='')
    print()

Submission status: Wrong Answer

Solution code:
N = int(input())

s = input()


def fnc(x1, x2):
    pre = x1
    curr = x2
    ans = [x1]
    for i in range(1, N):
        if curr == 1:  # 羊
            if s[i] == 'o':
                nv = pre
            else:
                nv = (pre + 1) % 2
        else:  # 狼
            if s[i] == 'x':
                nv = pre
            else:
                nv = (pre + 1) % 2
        pre = curr
        curr = nv
        ans.append(pre)

    if curr == x1:
        return ans
    else:
        return None


def solve():
    for i in [1, 0]:
        for j in [1, 0]:
            ans = fnc(i, j)
            if ans:
                return ans
    return None


if __name__ == '__main__':
    ans = solve()
    if not ans:
        print(-1)
        exit()

    for a in ans:
        print('S' if a else 'W', end='')
    print()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

def sw(sl,dp):
    for i in range(1,n-1):
        if sl[i]=="o" and dp[i]=="S":
            dp[i+1] =dp[i-1]
        elif sl[i] =="o" and dp[i]=="W":
            if dp[i-1] =="S":
                dp[i+1] = "W"
            else:
                dp[i+1] = "S"
        elif sl[i]=="x" and dp[i]=="S":
            if dp[i-1] =="S":
                dp[i+1] = "W"
            else:
                dp[i+1] = "S"
        else:
            dp[i+1] = dp[i-1]

sl = list(s)
dp =[0]*n
dp[0]="S"
dp[1]="S"
sw(sl,dp)

if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

dp =[0]*n
dp[0]="S"
dp[1]="W"
sw(sl,dp)

if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
    
dp =[0]*n
dp[0]="W"
dp[1]="S"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
        
dp =[0]*n
dp[0]="W"
dp[1]="W"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

def sw(sl,dp):
    for i in range(1,n-1):
        if sl[i]=="o" and dp[i]=="S":
            dp[i+1] =dp[i-1]
        elif sl[i] =="o" and dp[i]=="W":
            if dp[i-1] =="S":
                dp[i+1] = "W"
            else:
                dp[i+1] = "S"
        elif sl[i]=="x" and dp[i]=="S":
            if dp[i-1] =="S":
                dp[i+1] = "W"
            else:
                dp[i+1] = "S"
        else:
            dp[i+1] = dp[i-1]

sl = list(s)
dp =[0]*n
dp[0]="S"
dp[1]="S"
sw(sl,dp)

if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

dp =[0]*n
dp[0]="S"
dp[1]="W"
sw(sl,dp)

if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
    
dp =[0]*n
dp[0]="W"
dp[1]="S"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
        
dp =[0]*n
dp[0]="W"
dp[1]="W"
sw(sl,dp)
if sl[0] =="o":
    if dp[n-1] =="W":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="W":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="W":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass
else:
    if dp[n-1] =="S":
        pass
    elif sl[n-1] =="x":
        if dp[n-2] =="S":
            pass
        else:
            res = ''.join(dp)
            print(res)
            exit()
    elif sl[n-1] =="o":
        if dp[n-2] =="S":
            res = ''.join(dp)
            print(res)
            exit()
        else:
            pass

Submission status: Wrong Answer

Solution code:
def check(li,N):
    for i in range(N):
        if (s[i]=='o' and li[i]==0)or(s[i]=='x' and li[i]==1):
            if(li[(i+1)%N]!=-1 and li[(i+1)%N]!=li[i-1]):
                return False
            else:
                li[(i+1)%N]=li[i-1]
        elif (s[i]=='o' and li[i]==1)or(s[i]=='x' and li[i]==0):
            if(li[(i+1)%N]!=-1 and li[(i+1)%N]==li[i-1]):
                return False
            else:
                li[(i+1)%N]=int(not li[i-1])
    return True
    
def output(li):
    for i in range(N):
        if li[i]==1:
            print('W',end='')
        else:
            print('S',end='')
    print()

N=int(input())
s=input()
if s[0]=='o':
    for i in range(2):
        for j in range(2):
            li=[-1]*N
            li[0]=i
            if(i==0):
                li[-1]=j;li[1]=j
            else:
                li[-1]=j;li[1]=int(not j)
            if(check(li,N)):
                output(li)
                exit()
print(-1)

Submission status: Wrong Answer

Solution code:
def check(arr,N):
    for i in range(1,N):
        if s[i]=='o':
            if(li[i]==0):
                if(li[(i+1)%N]!=-1 and li[(i+1)%N]!=li[i-1]):
                    return False
                else:
                    li[(i+1)%N]=li[i-1]
            elif(li[i]==1):
                if(li[(i+1)%N]!=-1 and li[(i+1)%N]==li[i-1]):
                    return False
                else:
                    li[(i+1)%N]=int(not li[i-1])
        elif s[i]=='x':
            if(li[i]==0):
                if(li[(i+1)%N]!=-1 and li[(i+1)%N]==li[i-1]):
                    return False
                else:
                    li[(i+1)%N]=int(not li[i-1])
            elif(li[i]==1):
                if(li[(i+1)%N]!=-1 and li[(i+1)%N]!=li[i-1]):
                    return False
                else:
                    li[(i+1)%N]=li[i-1]
    return True

import itertools
N=int(input())
s=input()
ans=[]
if s[0]=='o':
    for i in range(2):
        for j in range(2):
            li=[-1]*N
            li[0]=i
            if(i==0):
                li[-1]=j;li[1]=j
            else:
                li[-1]=j;li[1]=int(not j)
            if(check(li,N)):
                ans=li
                break
if not ans:
    print(-1)
else:
    for i in range(N):
        if ans[i]==1:
            print('W',end='')
        else:
            print('S',end='')
    print()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()

    # 0番目と1番目を決めれば他が全部決まる
    for s0, s1 in [("S", "W"), ("W", "S"), ("S", "S"), ("W", "W")]:
        ans = [None] * N
        ans[0] = s0
        ans[1] = s1
        for i in range(1, N - 1):
            if ans[i] == "S":
                s = S[i]
            else:
                if S[i] == "o":
                    s = "x"
                else:
                    s = "o"

            if s == "o":
                ans[i + 1] = ans[i - 1]
            else:
                if ans[i - 1] == "S":
                    ans[i + 1] = "W"
                else:
                    ans[i + 1] = "S"

        if ans[-1] == "S":
            if S[-1] == "o":
                if ans[-2] == ans[0]:
                    print(*ans, sep="")
                    return
                else:
                    continue
            else:
                if ans[-2] != ans[0]:
                    print(*ans, sep="")
                    return
                else:
                    continue
        else:
            if S[-1] == "o":
                if ans[-2] != ans[0]:
                    print(*ans, sep="")
                    return
                else:
                    continue
            else:
                if ans[-2] == ans[0]:
                    print(*ans, sep="")
                    return
                else:
                    continue
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
    
for i in range(4):
  ans=[0]*N
  if i==0:
    ans[-1]="S"
    ans[0]="S"
  elif i==1:
    ans[-1]="S"
    ans[0]="W"
  elif i==2:
    ans[-1]="W"
    ans[0]="S"
  else:
    ans[-1]="W"
    ans[0]="W"
  
  for j,s in enumerate(S):
    if j!=N-1 and j!=N-2:
      if ans[j]=="S":
        if s=="o":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
      else:
        if s=="x":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
          
    else:
      flag=0
      if ans[N-2]=="S":
        if s=="o":
          if ans[N-1]!=ans[N-3]:
            flag=1
        else:
          if ans[N-1]==ans[N-3]:
            flag=1
      else:
        if s=="x":
          if ans[N-1]!=ans[N-3]:
            flag=1
        else:
          if ans[N-1]==ans[N-3]:
            flag=1
      if flag==0:
        continue
      if ans[N-1]=="S":
        if s=="o":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
      else:
        if s=="x":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
    
for i in range(4):
  ans=[0]*N
  if i==0:
    ans[-1]="S"
    ans[0]="S"
  elif i==1:
    ans[-1]="S"
    ans[0]="W"
  elif i==2:
    ans[-1]="W"
    ans[0]="S"
  else:
    ans[-1]="W"
    ans[0]="W"
  
  for j,s in enumerate(S):
    if j!=N-1:
      if ans[j]=="S":
        if s=="o":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
      else:
        if s=="x":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
          
    else:
      if ans[j]=="S":
        if s=="o":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
      else:
        if s=="x":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
# S = 1 W = -1
ss = [1,1]
sw = [1,-1]
ws = [-1,1]
ww = [-1,-1]
ans = []
for i in range(1,n):
  flag = 1
  if s[i] == "x":
    flag = -1
  if ss[i] == 1:
    ss.append(flag*ss[i-1])
  else:
    ss.append(flag*-ss[i-1])
  if sw[i] == 1:
    sw.append(flag*sw[i-1])
  else:
    sw.append(flag*-sw[i-1])
  if ws[i] == 1:
    ws.append(flag*ws[i-1])
  else:
    ws.append(flag*-ws[i-1])
  if ww[i] == 1:
    ww.append(flag*ww[i-1])
  else:
    ww.append(flag*-ww[i-1])
if ss[0] == ss[-1]:
  ans = ss
elif sw[0] == sw[-1]:
  ans = sw
elif ws[0] == ws[-1]:
  ans = ws
elif ww[0] == ww[-1]:
  ans = ww
if ans == []:
  print(-1)
else:
  ans = ans[:n]
  ans = ["S" if i == 1 else "W" for i in ans]
  print("".join(ans))

Submission status: Wrong Answer

Solution code:
def get_next(sw_prev2,sw_prev1,ox_prev1):
    
    rev_ox = {"o":"x", "x":"o"}
    rev_sw = {"S":"W", "W":"S"}
    
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()


for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans = ""
    ans = sw0+sw1
    for i,oxi in enumerate(ox[1:],1):
        ans += get_next(ans[i-1],ans[i],oxi)
    
    if ans[0] == ans[-1]:
        ans = ans[:-1]
        break
else:
    ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
def get_next(sw_prev2,sw_prev1,ox_prev1):
    
    rev_ox = {"o":"x", "x":"o"}
    rev_sw = {"S":"W", "W":"S"}
    
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()


ans = [None] * (n+1)
for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans[0] = sw0
    ans[1] = sw1
    for i,oxi in enumerate(ox[1:],1):
        swi = get_next(ans[i-1],ans[i],oxi)
        ans[i+1] = swi
    
    if ans[0] == ans[-1]:
        break
else:
    ans = [-1]

print("".join(map(str,ans[:n])))