Submission #1474842


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);
   
         int 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.println("S");
                         }else{
                             System.out.println("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 0
Code Size 2844 Byte
Status RE
Exec Time 144 ms
Memory 26028 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
RE × 3
RE × 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 RE 95 ms 23764 KB
00_example_02.txt RE 92 ms 19540 KB
00_example_03.txt RE 91 ms 19668 KB
01.txt RE 130 ms 23380 KB
02.txt RE 123 ms 19028 KB
03.txt RE 100 ms 18900 KB
04.txt RE 91 ms 18772 KB
05.txt RE 144 ms 22868 KB
06.txt RE 137 ms 25812 KB
07.txt RE 119 ms 21716 KB
08.txt RE 106 ms 21204 KB
09.txt RE 99 ms 19668 KB
10.txt RE 116 ms 19028 KB
11.txt RE 138 ms 21408 KB
12.txt RE 138 ms 25812 KB
13.txt RE 138 ms 26028 KB