結果

問題 No.701 ひとりしりとり
ユーザー taotao54321taotao54321
提出日時 2018-09-28 21:49:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,149 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 156,012 KB
実行使用メモリ 22,272 KB
最終ジャッジ日時 2024-04-20 10:21:06
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
22,016 KB
testcase_01 AC 36 ms
22,272 KB
testcase_02 AC 36 ms
22,144 KB
testcase_03 AC 37 ms
22,272 KB
testcase_04 AC 37 ms
22,144 KB
testcase_05 AC 36 ms
22,144 KB
testcase_06 AC 37 ms
22,144 KB
testcase_07 AC 36 ms
22,272 KB
testcase_08 AC 36 ms
22,272 KB
testcase_09 AC 38 ms
22,016 KB
testcase_10 AC 49 ms
22,144 KB
testcase_11 AC 166 ms
22,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };

    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($tokens:expr)  => {};
    ($tokens:expr,) => {};

    ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($tokens, $t);
        input_inner! { $tokens $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($tokens:expr, ( $($t:tt),* )) => {
        $(read_value!($tokens, $t)),*
    };

    ($tokens:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($tokens, $t)).collect::<Vec<_>>()
    };

    ($tokens:expr, chars) => {
        read_value!($tokens, String).chars().collect::<Vec<_>>()
    };

    ($tokens:expr, usize1) => {
        read_value!($tokens, usize) - 1
    };

    ($tokens:expr, $t:ty) => {
        $tokens.next().unwrap().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input! {
        N: usize,
    }

    let mut words = vec![Vec::<String>::new(); 13];
    for b1 in b'a'..b'n' {
        for b2 in b'a'..b'n' {
            for b3 in b'a'..b'n' {
                for b4 in b'a'..b'n' {
                    for b5 in b'a'..b'n' {
                        let bytes = [b1,b2,b3,b4,b5];
                        let word = String::from_utf8_lossy(&bytes);
                        words[(b1-b'a') as usize].push(word.to_string());
                    }
                }
            }
        }
    }

    let mut head = 0;
    for _ in 0..N-1 {
        let word = words[head].pop().unwrap();
        head = (word.as_bytes()[word.len()-1] - b'a') as usize;
        println!("{}", word);
    }

    let mut word = words[head].pop().unwrap();
    word.push('n');
    println!("{}", word);
}
0