Submission #1474843


Source Code Expand

import java.util.*;

public class Main {          
    
    static int N;
    static char[] cs;    
    
    public static void main(String[] args){           
        
         Scanner sc = new Scanner(System.in);
   
         N = sc.nextInt();         
         
         String S = sc.next();
         
         cs = S.toCharArray();
    
         for(int i = 0;i < 2;i++){
            for(int j = 0;j < 2;j++){
                
                int a[] = new int[N];  
                
                a[0] = i;
                a[1] = j;
                 
                if(cal(a)){                                                                                    
                     for(int k = 0;k < N;k++){
                         if(a[k] == 1){
                             System.out.print("S");
                         }else{
                             System.out.print("W");                             
                         }
                     }
                     System.out.println();
                     return;
                }                                                   
                 
            }
         }           
         
         System.out.println(-1);
         
  }    
    
   static boolean cal(int[] a){
       
            for (int i = 2; i < N; i++) {
                if (cs[i - 1] == 'o') {
                    if (a[i - 1] == 1) {
                        a[i] = a[i - 2];
                    } else {
                        a[i] = a[i - 2] ^ 1;
                    }
                } else {
                    if (a[i - 1] == 1) {
                        a[i] = a[i - 2] ^ 1;
                    } else {
                        a[i] = a[i - 2];
                    }
                }
            }

            if (a[0] == 1) {
                if (cs[0] == 'o') {
                    if (a[1] != a[N - 1]) return false;
                }
                if (cs[0] == 'x') {
                    if (a[1] == a[N - 1]) return false;
                }
            } else {
                if (cs[0] == 'o') {
                    if (a[1] == a[N - 1]) return false;
                }
                if (cs[0] == 'x') {
                    if (a[1] != a[N - 1]) return false;
                }
            }

            // check n-1
            if (cs[N - 1] == 'o') {
                if (a[N - 1] == 1) {
                    return a[N - 2] == a[0];
                } else {
                    return a[N - 2] != a[0];
                }
            } else {
                if (a[N - 1] == 1) {
                    return a[N - 2] != a[0];
                } else {
                    return a[N - 2] == a[0];
                }
            }            
    }                              
}

Submission Info

Submission Time
Task D - Menagerie
User suesue
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 2853 Byte
Status AC
Exec Time 437 ms
Memory 31380 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 91 ms 19540 KB
00_example_02.txt AC 89 ms 18900 KB
00_example_03.txt AC 90 ms 19924 KB
01.txt AC 346 ms 29004 KB
02.txt AC 305 ms 26688 KB
03.txt AC 113 ms 21844 KB
04.txt AC 88 ms 21844 KB
05.txt AC 402 ms 31380 KB
06.txt AC 403 ms 31344 KB
07.txt AC 200 ms 25736 KB
08.txt AC 210 ms 24516 KB
09.txt AC 131 ms 21076 KB
10.txt AC 111 ms 21076 KB
11.txt AC 437 ms 28804 KB
12.txt AC 419 ms 31040 KB
13.txt AC 430 ms 26912 KB