Submission #1381114


Source Code Expand

import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static String s;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	s = scan.next();

	String ans = check(true, true);
	if(ans.equals("-1")) ans = check(true, false);
	if(ans.equals("-1")) ans = check(false, true);
	if(ans.equals("-1")) ans = check(false, false);

	System.out.println(ans);
	scan.close();
    }

    private static boolean next(boolean p, boolean c, char say) {
	boolean state = (say == 'o' ? p : !p);
	return c ? state : !state;
    }

    private static String check(boolean p, boolean c) {
	boolean[] state = new boolean[N+1];
	state[0] = p;
	state[1] = c;

	for (int i = 1; i < N; i++) {
	    state[i+1] = next(state[i-1], state[i], s.charAt(i));
	}

	String ans = "-1";
	if(state[N] == state[0] && next(state[N-1], state[0], s.charAt(0)) == state[1]) {
	    StringBuilder str = new StringBuilder(N);
	    for (int i = 0; i < N; i++) {
		str.append(state[i] ? 'S' : 'W');
	    }
	    ans = str.toString();
	}
	return ans;
    }
}

Submission Info

Submission Time
Task D - Menagerie
User tkyobc
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 1175 Byte
Status AC
Exec Time 172 ms
Memory 25620 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 16
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 92 ms 21712 KB
00_example_02.txt AC 87 ms 19796 KB
00_example_03.txt AC 93 ms 19924 KB
01.txt AC 161 ms 23376 KB
02.txt AC 139 ms 23168 KB
03.txt AC 101 ms 21716 KB
04.txt AC 89 ms 21972 KB
05.txt AC 162 ms 21860 KB
06.txt AC 150 ms 24104 KB
07.txt AC 124 ms 19156 KB
08.txt AC 126 ms 21588 KB
09.txt AC 109 ms 19156 KB
10.txt AC 124 ms 21332 KB
11.txt AC 164 ms 24736 KB
12.txt AC 168 ms 25620 KB
13.txt AC 172 ms 25484 KB