結果

問題 No.676 C0nvertPr0b1em
ユーザー lzy9lzy9
提出日時 2018-04-27 22:26:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,809 bytes
コンパイル時間 5,508 ms
コンパイル使用メモリ 143,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 17:00:40
合計ジャッジ時間 2,082 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::collections::{HashMap, VecDeque};

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
static DX: &'static [i32] = &[0, 0, 1, -1];
#[allow(dead_code)]
static DY: &'static [i32] = &[1, -1, 0, 0];
#[allow(dead_code)]
static MOD: u64 = 1000000007;

fn main() {
    let s: String = read();

    for c in s.chars() {
        if c == 'I' || c == 'l' {
            print!("{}", 1);
        } else if c == 'O' || c == 'o' {
            print!("{}", 0);
        } else {
            print!("{}", c);
        }
    }

    println!();
}

#[allow(dead_code)]
struct SegTree<T> where T: Clone + Copy {
    n: usize,
    dat: Vec<T>,
    operation: fn(T, T) -> T,
    default: T,
}

impl<T> SegTree<T> where T: Clone + Copy {
    #[allow(dead_code)]
    fn new(n: usize, operation: fn(T, T) -> T, default: T) -> Self {
        let mut size = 1;

        while size < n {
            size <<= 1;
        }

        SegTree {
            n: size,
            dat: vec![default; size * 2],
            operation,
            default,
        }
    }

    #[allow(dead_code)]
    fn update(&mut self, idx: usize, x: T) {
        let mut k = idx + self.n - 1;

        self.dat[k] = x;

        while 0 < k {
            k = (k - 1) / 2;

            self.dat[k] = (self.operation)(self.dat[k * 2 + 1], self.dat[k * 2 + 2]);
        }
    }

    #[allow(dead_code)]
    fn query(&self, from: usize, to: usize) -> T {
        self.query_rec(from, to, 0, 0, self.n)
    }

    #[allow(dead_code)]
    fn query_rec(&self, from: usize, to: usize, idx: usize, a: usize, b: usize) -> T {
        if b <= from || to <= a {
            return self.default;
        }

        if from <= a && b <= to {
            return self.dat[idx];
        }

        let mid = (a + b) / 2;

        (self.operation)(self.query_rec(from, to, idx * 2 + 1, a, mid), self.query_rec(from, to, idx * 2 + 2, mid, b))
    }
}

#[allow(dead_code)]
struct SCC {
    groups: Vec<Vec<usize>>,
    index: Vec<usize>,
    parent: Vec<Option<usize>>,
}

#[allow(dead_code)]
impl SCC {
    #[allow(dead_code)]
    fn new(graph: &Vec<Vec<usize>>) -> Self {
        let (groups, index, parent) = SCC::make(graph);

        SCC {
            groups,
            index,
            parent
        }
    }

    #[allow(dead_code)]
    fn make(graph: &Vec<Vec<usize>>) -> (Vec<Vec<usize>>, Vec<usize>, Vec<Option<usize>>) {
        let n = graph.len();
        let mut stack: Vec<usize> = Vec::new();
        let mut visited: Vec<bool> = vec![false; n];
        let mut parent: Vec<Option<usize>> = vec![None; n];

        let mut rgraph: Vec<Vec<usize>> = (0..n).map(|_| Vec::new()).collect();

        for i in 0..n {
            for j in graph[i].iter() {
                rgraph[*j].push(i);
            }

            if !visited[i] {
                SCC::init_dfs(graph, i, &mut stack, &mut visited, &mut parent);
            }
        }

        let mut groups: Vec<Vec<usize>> = Vec::new();
        let mut index: Vec<usize> = vec![0; n];
        let mut done: Vec<bool> = vec![false; n];
        let mut i = 0;

        while let Some(node) = stack.pop() {
            if !done[node] {
                let mut group = Vec::new();
                SCC::make_dfs(&rgraph, node, &mut done, &mut group);

                for member in group.iter() {
                    index[*member] = i;
                }

                groups.push(group);
                i += 1;
            }
        }

        (groups, index, parent)
    }

    #[allow(dead_code)]
    fn init_dfs(graph: &Vec<Vec<usize>>, current: usize, stack: &mut Vec<usize>, visited: &mut Vec<bool>, parent: &mut Vec<Option<usize>>) {
        visited[current] = true;

        for next in graph[current].iter() {
            if !visited[*next] {
                parent[*next] = Some(current);
                SCC::init_dfs(graph, *next, stack, visited, parent);
            }
        }

        stack.push(current);
    }

    #[allow(dead_code)]
    fn make_dfs(rgraph: &Vec<Vec<usize>>, current: usize, done: &mut Vec<bool>, group: &mut Vec<usize>) {
        group.push(current);
        done[current] = true;

        for next in rgraph[current].iter() {
            if !done[*next] {
                SCC::make_dfs(rgraph, *next, done, group);
            }
        }
    }
}
0