Problems Submissions
Register Login 質問(Gitter) GitHub

Submit Info #3601

Problem Lang User Status Time Memory
Suffix Array rust (anonymous) WA 923 ms 31.03 MiB

ケース詳細
Name Status Time Memory
all_same_00 AC 285 ms 30.68 MiB
all_same_01 AC 284 ms 30.88 MiB
all_same_02 AC 285 ms 30.84 MiB
all_same_03 AC 283 ms 30.79 MiB
all_same_04 AC 286 ms 30.64 MiB
example_00 AC 5 ms 0.62 MiB
example_01 WA 5 ms 0.59 MiB
example_02 AC 5 ms 0.70 MiB
example_03 AC 4 ms 0.63 MiB
fib_str_00 AC 376 ms 31.03 MiB
fib_str_01 AC 253 ms 22.95 MiB
fib_str_02 AC 253 ms 21.79 MiB
fib_str_03 AC 230 ms 19.98 MiB
fib_str_04 AC 364 ms 30.34 MiB
max_random_00 AC 897 ms 30.63 MiB
max_random_01 AC 912 ms 30.86 MiB
max_random_02 AC 923 ms 30.84 MiB
max_random_03 AC 906 ms 30.79 MiB
max_random_04 AC 891 ms 30.65 MiB
random_00 AC 504 ms 24.44 MiB
random_01 AC 764 ms 28.98 MiB
random_02 AC 27 ms 3.96 MiB
random_03 AC 634 ms 26.88 MiB
random_04 AC 202 ms 17.51 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 } } } fn solve() { let s = read!(String); 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 = vec![0;n]; let mut c = vec![0;n]; let mut cnt = vec![0;n]; let mut k = 1; for i in 0..n { cnt[a[i]]+=1; } for i in 0..n-1 { cnt[i+1] += cnt[i]; } for i in (0..n).rev() { cnt[a[i]] -= 1; p[cnt[a[i]]] = i; } let mut class = 0; c[p[0]]= class; for i in 1..n { if a[p[i]]!=a[p[i-1]] { class += 1; } c[p[i]] = class; } // for i in 0..n { // print!("{} ", p[i]); // } // println!(); // for i in 0..n { // print!("{} ", c[i]); // } // println!(); loop { k *= 2; // println!("{}", k); if k>2*n {break;} for i in 0..n { let ni = if k/2<=p[i] {p[i]-k/2} else {p[i]+n-k/2}; p[i] = ni; } // for i in 0..n { // print!("{} ", p[i]); // } // println!(); let mut ncnt = vec![0;n]; for i in 0..n { ncnt[c[p[i]]] += 1; // print!("{}", c[p[i]]); } // println!(); // for i in 0..n { // print!("{} ", ncnt[i]); // } // println!(); for i in 0..n-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]; // println!("{} {} {} {}", i, p[i], c[p[i]], ncnt[c[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; // for i in 0..n { // print!("{} ", p[i]); // } // println!(); // for i in 0..n { // print!("{} ", c[i]); // } // println!(); } for i in 1..n { print!("{} ", p[i]); } println!(); } fn run() { solve(); }