結果

問題 No.104 国道
ユーザー yukyuyukyu
提出日時 2021-03-08 00:28:00
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,226 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 149,876 KB
実行使用メモリ 132,864 KB
最終ジャッジ日時 2024-04-17 16:37:26
合計ジャッジ時間 2,610 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 6 ms
9,984 KB
testcase_15 AC 91 ms
132,864 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn main() {
    exec(read());
}

fn exec(i: String) {
    if i.is_empty() {
        return println!("{}", 1);
    }
    let char_list: Vec<char> = i.chars().collect();
    let length = char_list.len();
    let start = multiple(length);
    let end = multiple(length + 1);
    let last_line_numbers: Vec<i64> = (start..end).collect();
    let index = get_index(char_list);
    println!("{}", last_line_numbers[index - 1]);
}

fn multiple(i: usize) -> i64 {
    rec_power2(i, 1)
}

fn rec_power2(i: usize, acc: i64) -> i64 {
    if i == 0 {
        return acc;
    } else {
        rec_power2(i - 1, acc * 2)
    }
}

fn get_index(mut l: Vec<char>) -> usize {
    let head = l.remove(0);
    if head == 'L' {
        rec_get_index(l, 1)
    } else {
        rec_get_index(l, 2)
    }
}

fn rec_get_index(mut l: Vec<char>, acc: usize) -> usize {
    if l.is_empty() {
        return acc;
    }

    let head = l.remove(0);
    if head == 'L' {
        return rec_get_index(l, (acc * 2) - 1);
    } else {
        return rec_get_index(l, acc * 2);
    }
}

fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
0