Submission #1116662


Source Code Expand

import java.util.Scanner;

public class Main {	
	
	private static int[] values = new int[100010];
	private static final int WOLF = 0 , SHEEP = 1;
	// o sheep both same
	// x wolf both same
	
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String input = scan.next() , ans = null;
		
		for (int i = 0;i < 2;i ++) {
			for (int j = 0;j < 2;j ++) {
				String temp = check(input , i , j);
				if (temp != null) {
					ans = temp;
					break;
				}
				if (ans != null)
					break;
			}	
		}
		if (ans == null)
			System.out.println(- 1);
		else
			System.out.println(ans);
		
	}
	
	private static int getValue(int current , int value , char ch) {
		
		if (current == WOLF) {
			if (ch == 'x') {
				return value;
			} else {
				return 1 - value;
			}
		} else {
			if (ch == 'o') {
				return value;
			} else {
				return 1 - value;
			}
		}
		
	}
	
	private static boolean check(int current , int left , int right , char ch) {
	
		if (current == WOLF) {
			if (ch == 'x') {
				if (left != right)
					return false;
			} else {
				if (left == right)
					return false;
			}
		} else {
			if (ch == 'o') {
				if (left != right)
					return false;
			} else {
				if (left == right)
					return false;
			}
		}
		return true;
		 
	}
	
	private static String check(String input , int value1 , int value2) {
		
		values[0] = value1;
		values[1] = value2;
		for (int i = 2;i < input.length();i ++) {
			values[i] = getValue(values[i - 1] , values[i - 2] , input.charAt(i - 1));
		}
		int length = input.length();
		for (int i = 0;i < length;i ++) {
			int left = (i == 0) ? (length - 1) : i - 1;
			int right = (i == length - 1) ? 0 : i + 1;
			char ch = input.charAt(i);
			if (!check(values[i] , values[left] , values[right] , ch)) {
				return null;
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int i = 0;i < length;i ++) {
			if (values[i] == WOLF)
				builder.append("W");
			else
				builder.append("S");
		}
		return builder.toString();
		
	}
	
		
}












Submission Info

Submission Time
Task D - Menagerie
User nevergiveup
Language Java7 (OpenJDK 1.7.0)
Score 500
Code Size 2165 Byte
Status AC
Exec Time 261 ms
Memory 26516 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 93 ms 20820 KB
00_example_02.txt AC 94 ms 20692 KB
00_example_03.txt AC 93 ms 18900 KB
01.txt AC 245 ms 26516 KB
02.txt AC 244 ms 24728 KB
03.txt AC 110 ms 21204 KB
04.txt AC 94 ms 18900 KB
05.txt AC 236 ms 23572 KB
06.txt AC 237 ms 24416 KB
07.txt AC 179 ms 22064 KB
08.txt AC 193 ms 24388 KB
09.txt AC 131 ms 21844 KB
10.txt AC 178 ms 22124 KB
11.txt AC 261 ms 26116 KB
12.txt AC 255 ms 24124 KB
13.txt AC 238 ms 24036 KB