結果
問題 | No.1725 [Cherry 3rd Tune D] 無言の言葉 |
ユーザー | koba-e964 |
提出日時 | 2021-10-29 22:01:06 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 230 ms / 4,000 ms |
コード長 | 3,075 bytes |
コンパイル時間 | 12,871 ms |
コンパイル使用メモリ | 388,620 KB |
実行使用メモリ | 43,392 KB |
最終ジャッジ日時 | 2024-10-07 11:16:03 |
合計ジャッジ時間 | 17,139 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,820 KB |
testcase_07 | AC | 3 ms
6,816 KB |
testcase_08 | AC | 3 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 1 ms
6,820 KB |
testcase_12 | AC | 6 ms
6,816 KB |
testcase_13 | AC | 6 ms
6,816 KB |
testcase_14 | AC | 31 ms
6,816 KB |
testcase_15 | AC | 6 ms
6,820 KB |
testcase_16 | AC | 8 ms
6,816 KB |
testcase_17 | AC | 11 ms
6,820 KB |
testcase_18 | AC | 34 ms
6,820 KB |
testcase_19 | AC | 10 ms
6,820 KB |
testcase_20 | AC | 5 ms
6,816 KB |
testcase_21 | AC | 34 ms
6,816 KB |
testcase_22 | AC | 66 ms
16,220 KB |
testcase_23 | AC | 67 ms
14,584 KB |
testcase_24 | AC | 46 ms
10,796 KB |
testcase_25 | AC | 72 ms
23,508 KB |
testcase_26 | AC | 63 ms
18,816 KB |
testcase_27 | AC | 56 ms
26,240 KB |
testcase_28 | AC | 83 ms
25,472 KB |
testcase_29 | AC | 81 ms
24,324 KB |
testcase_30 | AC | 74 ms
28,796 KB |
testcase_31 | AC | 52 ms
14,336 KB |
testcase_32 | AC | 88 ms
38,756 KB |
testcase_33 | AC | 88 ms
40,008 KB |
testcase_34 | AC | 88 ms
36,992 KB |
testcase_35 | AC | 86 ms
33,024 KB |
testcase_36 | AC | 86 ms
36,212 KB |
testcase_37 | AC | 219 ms
5,248 KB |
testcase_38 | AC | 230 ms
5,248 KB |
testcase_39 | AC | 230 ms
5,248 KB |
testcase_40 | AC | 227 ms
5,248 KB |
testcase_41 | AC | 229 ms
5,248 KB |
testcase_42 | AC | 1 ms
5,248 KB |
testcase_43 | AC | 20 ms
43,392 KB |
ソースコード
use std::cmp::*; 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),* )) => { ($(read_value!($next, $t)),*) }; ($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")); } fn dfs(k: usize, l: i64, r: i64, c: usize, len: &[i64], x: &[[i64; 26]], y: &[[i64; 26]]) -> i64 { if l == r { return 0; } if k == 1 { return x[r as usize][c] - x[l as usize][c]; } assert!(r <= len[k]); assert!(l <= r); if (l, r) == (0, len[k]) { let mut a = y[y.len() - 1][c]; let b = dfs(k - 1, 0, len[k - 1], c, len, x, y); a += 2 * b; return a; } let mut a = 0; let mid1 = len[k - 1]; let mid2 = len[k] - len[k - 1]; if l < mid1 { let b = dfs(k - 1, l, min(r, mid1), c, &len, x, y); a += b; } if l < mid2 && r > mid1 { let lidx = (max(l, mid1) - mid1) as usize; let ridx = (min(r, mid2) - mid1) as usize; a += y[ridx][c] - y[lidx][c]; } if r > mid2 { let b = dfs(k - 1, len[k - 1] - (r - mid2), len[k - 1] - (max(l, mid2) - mid2), c, &len, x, y); a += b; } a } fn main() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} input! { x: chars, y: chars, q: usize, lrc: [(i64, i64, char); q], } fn prepare(x: &[char]) -> Vec<[i64; 26]> { let n = x.len(); let mut dp = vec![[0; 26]; n + 1]; for i in 0..n { dp[i + 1] = dp[i]; dp[i + 1][(x[i] as u8 - b'a') as usize] += 1; } dp } let dpx = prepare(&x); let dpy = prepare(&y); let mut len = vec![0, x.len() as i64]; let mut cur = x.len() as i64; let mut idx = 1; while cur < 1i64 << 30 { cur = 2 * cur + y.len() as i64; idx += 1; len.push(cur); } for (l, r, c) in lrc { puts!("{}\n", dfs(idx, l - 1, r, (c as u8 - b'a') as _, &len, &dpx, &dpy)); } }