Problems Submissions
Register Login 質問(Gitter) GitHub

Submit Info #3604

Problem Lang User Status Time Memory
Suffix Array rust (anonymous) AC 955 ms 23.99 MiB

ケース詳細
Name Status Time Memory
all_same_00 AC 292 ms 23.66 MiB
all_same_01 AC 293 ms 23.88 MiB
all_same_02 AC 293 ms 23.87 MiB
all_same_03 AC 294 ms 23.79 MiB
all_same_04 AC 291 ms 23.75 MiB
example_00 AC 5 ms 0.67 MiB
example_01 AC 6 ms 0.64 MiB
example_02 AC 5 ms 0.62 MiB
example_03 AC 6 ms 0.64 MiB
fib_str_00 AC 400 ms 23.99 MiB
fib_str_01 AC 264 ms 17.75 MiB
fib_str_02 AC 264 ms 16.96 MiB
fib_str_03 AC 240 ms 15.59 MiB
fib_str_04 AC 381 ms 23.41 MiB
max_random_00 AC 898 ms 23.74 MiB
max_random_01 AC 896 ms 23.89 MiB
max_random_02 AC 955 ms 23.82 MiB
max_random_03 AC 896 ms 23.86 MiB
max_random_04 AC 901 ms 23.69 MiB
random_00 AC 511 ms 19.00 MiB
random_01 AC 773 ms 22.40 MiB
random_02 AC 30 ms 3.36 MiB
random_03 AC 644 ms 20.83 MiB
random_04 AC 215 ms 13.67 MiB

#![allow(unused_imports)] #![allow(non_snake_case, unused)] use std::cmp::*; use std::collections::*; use std::ops::*; macro_rules! eprint { ($($t:tt)*) => {{ use ::std::io::Write; let _ = write!(::std::io::stderr(), $($t)*); }}; } macro_rules! eprintln { () => { eprintln!(""); }; ($($t:tt)*) => {{ use ::std::io::Write; let _ = writeln!(::std::io::stderr(), $($t)*); }}; } macro_rules! dbg { ($v:expr) => {{ let val = $v; eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val); val }} } macro_rules! mat { ($($e:expr),*) => { Vec::from(vec![$($e),*]) }; ($($e:expr,)*) => { Vec::from(vec![$($e),*]) }; ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) }; ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) }; } macro_rules! ok { ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => { $a$([$i])*.$f($($t),*) }; ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { { let t = $e; ok!($a$([$i])*.$f($($es),*)$(@$t)*@t) } }; } pub fn readln() -> String { let mut line = String::new(); ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e)); line } macro_rules! read { ($($t:tt),*; $n:expr) => {{ let stdin = ::std::io::stdin(); let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| { let line = line.unwrap(); let mut it = line.split_whitespace(); _read!(it; $($t),*) }).collect::<Vec<_>>(); ret }}; ($($t:tt),*) => {{ let line = readln(); let mut it = line.split_whitespace(); _read!(it; $($t),*) }}; } macro_rules! _read { ($it:ident; [char]) => { _read!($it; String).chars().collect::<Vec<_>>() }; ($it:ident; [u8]) => { Vec::from(_read!($it; String).into_bytes()) }; ($it:ident; usize1) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1 }; ($it:ident; [usize1]) => { $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>() }; ($it:ident; [$t:ty]) => { $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>() }; ($it:ident; $t:ty) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e)) }; ($it:ident; $($t:tt),+) => { ($(_read!($it; $t)),*) }; } pub fn main() { let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join(); } const MOD: u32 = 1_000_000_007; const INF: usize = std::usize::MAX/2; pub trait SetMinMax { fn setmin(&mut self, v: Self) -> bool; fn setmax(&mut self, v: Self) -> bool; } impl<T> SetMinMax for T where T: PartialOrd { fn setmin(&mut self, v: T) -> bool { *self > v && { *self = v; true } } fn setmax(&mut self, v: T) -> bool { *self < v && { *self = v; true } } } // http://wk1080id.hatenablog.com/entry/2018/12/25/005926 fn suffix_array(s: String) -> Vec<usize> { let mut a = s.chars().map(|x| (x as usize) - ('a' as usize)+1).collect::<Vec<usize>>(); a.push(0); let n = a.len(); let mut p = (0..n).collect::<Vec<usize>>(); let mut c = a.clone(); let mut k = 1; loop { if k>2*n {break;} for i in 0..n { p[i] = if k/2<=p[i] {p[i]-k/2} else {p[i]+n-k/2}; } let mut ncnt = vec![0;max(27,n)]; for i in 0..n { ncnt[c[p[i]]] += 1; } for i in 0..ncnt.len()-1 { ncnt[i+1] += ncnt[i]; } let mut np = vec![0;n]; for i in (0..n).rev() { ncnt[c[p[i]]] -= 1; np[ncnt[c[p[i]]]] = p[i]; } let mut class = 0; let mut nc = vec![0;n]; nc[np[0]]= class; for i in 1..n { if c[np[i]]!=c[np[i-1]] || c[(np[i]+k/2)%n]!=c[(np[i-1]+k/2)%n]{ class += 1; } nc[np[i]] = class; } c = nc; p = np; k*=2; } (1..p.len()).map(|x| p[x]).collect::<Vec<usize>>() } fn solve() { let s = read!(String); let ans = suffix_array(s); for i in ans { print!("{} ", i); } println!(); } fn run() { solve(); }