AtCoder Regular Contest 069

Submission #1662439

Source codeソースコード

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

Task問題 D - Menagerie
User nameユーザ名 もふ
Created time投稿日時
Language言語 Rust (1.15.1)
Status状態 AC
Score得点 500
Source lengthソースコード長 1839 Byte
File nameファイル名
Exec time実行時間 17 ms
Memory usageメモリ使用量 4352 KB

Compiler messageコンパイルメッセージ

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() {
| ^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt,00_example_03.txt
All 500 / 500 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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