結果
問題 | No.958 たぷりすたべる (回文) |
ユーザー | koba-e964 |
提出日時 | 2021-11-04 19:52:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,003 bytes |
コンパイル時間 | 16,565 ms |
コンパイル使用メモリ | 378,604 KB |
実行使用メモリ | 11,500 KB |
最終ジャッジ日時 | 2024-10-15 01:53:53 |
合計ジャッジ時間 | 18,530 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 14 ms
5,248 KB |
testcase_38 | AC | 14 ms
5,248 KB |
testcase_39 | AC | 14 ms
5,248 KB |
testcase_40 | AC | 14 ms
5,248 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | AC | 54 ms
11,368 KB |
testcase_53 | WA | - |
testcase_54 | WA | - |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } // Manacher http://snuke.hatenablog.com/entry/2014/12/02/235837 // Verified by https://atcoder.jp/contests/wupc2019/submissions/4540033 fn manacher<T: PartialEq>(tmp: &[T]) -> Vec<usize> { let n = tmp.len(); let mut r = vec![0; n]; { let mut i = 0; let mut j = 0; while i < n { while i >= j && i + j < n && tmp[i - j] == tmp[i + j] { j += 1; } r[i] = j; let mut k = 1; while i >= k && i + k < n && k + r[i - k] < j { r[i + k] = r[i - k]; k += 1; } i += k; j -= k; } } r } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} input! { n: usize, k: i64, q: usize, s: chars, a: [i64; q], } let mut t = s.clone(); t.extend(&s); t.extend(&s); let dp = manacher(&t); for a in a { let a = a - 1; let idx = (a as usize % n) + n; let len = dp[idx] - 1; if idx >= len || idx + len + 1 >= 3 * n { puts!("{}\n", min(a, n as i64 * k - 1 - a) * 2 + 1); continue; } else { puts!("{}\n", 2 * len + 1); } } }