Submission #1662439


Source Code Expand

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;


fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    // SSS => o
    // SSW => x
    // SWS => x
    // SWW => o
    // WWW => o
    
    while let Some(N) = sc.read1() {
        let s = sc.read::<String>();
        let s: Vec<i32> = s.chars()
            .map(|e| if e == 'o' { 1 } else { 0 })
            .collect();

        let mut found = false;
        for i in 0..4 {
            let mut cand = vec![0 as i32; N];
            cand[0] = i & 1;
            cand[1] = (i >> 1) & 1;

            //  j.......
            // 012345678(N-1)
            for j in 2..N {
                cand[j] = cand[j - 2] ^ cand[j - 1] ^ s[j - 1];
            }

            if s[0] == cand[N - 1] ^ cand[0] ^ cand[1] && s[N - 1] == cand[N - 2] ^ cand[N - 1] ^ cand[0] {
                for e in cand {
                    print!("{}", if e == 1 { "S" } else { "W" });
                }
                println!();
                found = true;
                break;
            }
        }

        if !found {
            println!("-1");
        }
    }
}

//=============================================================================

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

Submission Info

Submission Time
Task D - Menagerie
User ir5
Language Rust (1.15.1)
Score 500
Code Size 1839 Byte
Status AC
Exec Time 17 ms
Memory 4352 KB

Compile Error

warning: variable `N` should have a snake case name such as `n`, #[warn(non_snake_case)] on by default
  --> ./Main.rs:16:20
   |
16 |     while let Some(N) = sc.read1() {
   |                    ^

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 2 ms 4352 KB
00_example_02.txt AC 2 ms 4352 KB
00_example_03.txt AC 2 ms 4352 KB
01.txt AC 14 ms 4352 KB
02.txt AC 9 ms 4352 KB
03.txt AC 2 ms 4352 KB
04.txt AC 2 ms 4352 KB
05.txt AC 16 ms 4352 KB
06.txt AC 16 ms 4352 KB
07.txt AC 4 ms 4352 KB
08.txt AC 4 ms 4352 KB
09.txt AC 3 ms 4352 KB
10.txt AC 2 ms 4352 KB
11.txt AC 17 ms 4352 KB
12.txt AC 17 ms 4352 KB
13.txt AC 17 ms 4352 KB