結果
問題 | No.676 C0nvertPr0b1em |
ユーザー | lzy9 |
提出日時 | 2018-04-27 22:26:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 4,809 bytes |
コンパイル時間 | 12,580 ms |
コンパイル使用メモリ | 378,380 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 12:31:07 |
合計ジャッジ時間 | 13,670 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#[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); } } } }