結果
問題 | No.1951 消えたAGCT(2) |
ユーザー | bqn |
提出日時 | 2022-05-23 12:01:05 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 471 ms / 3,000 ms |
コード長 | 9,218 bytes |
コンパイル時間 | 11,684 ms |
コンパイル使用メモリ | 378,340 KB |
実行使用メモリ | 58,820 KB |
最終ジャッジ日時 | 2024-09-20 13:04:04 |
合計ジャッジ時間 | 18,144 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 79 ms
56,644 KB |
testcase_09 | AC | 78 ms
58,692 KB |
testcase_10 | AC | 77 ms
58,692 KB |
testcase_11 | AC | 74 ms
56,772 KB |
testcase_12 | AC | 45 ms
34,864 KB |
testcase_13 | AC | 9 ms
5,376 KB |
testcase_14 | AC | 430 ms
55,124 KB |
testcase_15 | AC | 329 ms
44,812 KB |
testcase_16 | AC | 359 ms
47,292 KB |
testcase_17 | AC | 464 ms
58,692 KB |
testcase_18 | AC | 452 ms
58,564 KB |
testcase_19 | AC | 448 ms
58,700 KB |
testcase_20 | AC | 453 ms
58,816 KB |
testcase_21 | AC | 77 ms
56,772 KB |
testcase_22 | AC | 81 ms
56,776 KB |
testcase_23 | AC | 81 ms
58,820 KB |
testcase_24 | AC | 82 ms
58,696 KB |
testcase_25 | AC | 83 ms
58,688 KB |
testcase_26 | AC | 454 ms
58,816 KB |
testcase_27 | AC | 471 ms
58,688 KB |
コンパイルメッセージ
warning: unused macro definition: `input_inner` --> src/main.rs:89:14 | 89 | macro_rules! input_inner { | ^^^^^^^^^^^ | = note: `#[warn(unused_macros)]` on by default
ソースコード
#![allow(unused_parens)] #![allow(unused_imports)] #![allow(non_upper_case_globals)] #![allow(non_snake_case)] #![allow(unused_mut)] #![allow(unused_variables)] #![allow(dead_code)] type Vec2<T> = Vec<Vec<T>>; type Vec3<T> = Vec<Vec<Vec<T>>>; #[allow(unused_macros)] macro_rules! invec { ( $ t : ty ) => {{ let mut s = String::new(); match std::io::stdin().read_line(&mut s) { Ok(0) => Vec::<$t>::new(), Ok(n) => s .trim() .split_whitespace() .map(|s| s.parse::<$t>().unwrap()) .collect::<Vec<$t>>(), Err(_) => Vec::<$t>::new(), } }}; } #[allow(unused_macros)] macro_rules! get { ($t:ty) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty; $n:expr) => { (0..$n).map(|_| get!($t) ).collect::<Vec<_>>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| get!($($t),*) ).collect::<Vec<_>>() }; ($t:ty ;;) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::<Vec<_>>() } }; ($t:ty ;; $n:expr) => { (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>() }; } #[allow(unused_macros)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[allow(unused_macros)] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($next:expr, [$t:tt]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } #[allow(unused_macros)] #[cfg(debug_assertions)] macro_rules! mydbg { //($arg:expr) => (dbg!($arg)) //($arg:expr) => (println!("{:?}",$arg)); ($($a:expr),*) => { eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*); } } #[cfg(not(debug_assertions))] macro_rules! mydbg { ($($arg:expr),*) => {}; } macro_rules! echo { ($($a:expr),*) => { $(println!("{}",$a))* } } use std::cmp::*; use std::collections::*; use std::ops::{Add, Div, Mul, Rem, Sub}; trait SafeRangeContain { fn safe_contains(&self, x: i64) -> bool; } impl SafeRangeContain for std::ops::Range<usize> { fn safe_contains(&self, x: i64) -> bool { if x < 0 { return false; } return self.contains(&(x as usize)); } } #[allow(dead_code)] static INF_I64: i64 = i64::max_value() / 2; #[allow(dead_code)] static INF_I32: i32 = i32::max_value() / 2; #[allow(dead_code)] static INF_USIZE: usize = usize::max_value() / 2; #[allow(dead_code)] static M_O_D: usize = 1000000007; #[allow(dead_code)] static PAI: f64 = 3.1415926535897932; trait IteratorExt: Iterator { fn toVec(self) -> Vec<Self::Item>; } impl<T: Iterator> IteratorExt for T { fn toVec(self) -> Vec<Self::Item> { self.collect() } } trait CharExt { fn toNum(&self) -> usize; fn toAlphabetIndex(&self) -> usize; fn toNumIndex(&self) -> usize; } impl CharExt for char { fn toNum(&self) -> usize { return *self as usize; } fn toAlphabetIndex(&self) -> usize { return self.toNum() - 'a' as usize; } fn toNumIndex(&self) -> usize { return self.toNum() - '0' as usize; } } trait VectorExt { fn joinToString(&self, s: &str) -> String; } impl<T: ToString> VectorExt for Vec<T> { fn joinToString(&self, s: &str) -> String { return self .iter() .map(|x| x.to_string()) .collect::<Vec<_>>() .join(s); } } trait StringExt { fn get_reverse(&self) -> String; } impl StringExt for String { fn get_reverse(&self) -> String { self.chars().rev().collect::<String>() } } trait UsizeExt { fn pow(&self, n: usize) -> usize; } impl UsizeExt for usize { fn pow(&self, n: usize) -> usize { return ((*self as u64).pow(n as u32)) as usize; } } //https://github.com/rust-lang-ja/ac-library-rs pub mod fenwicktree { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree #[derive(Clone, Debug)] pub struct FenwickTree<T> { n: usize, ary: Vec<T>, e: T, } impl<T: Clone + std::ops::AddAssign<T>> FenwickTree<T> { pub fn new(n: usize, e: T) -> Self { FenwickTree { n, ary: vec![e.clone(); n], e, } } pub fn accum(&self, mut idx: usize) -> T { let mut sum = self.e.clone(); while idx > 0 { sum += self.ary[idx - 1].clone(); idx &= idx - 1; } sum } /// performs data[idx] += val; pub fn add<U: Clone>(&mut self, mut idx: usize, val: U) where T: std::ops::AddAssign<U>, { let n = self.n; idx += 1; while idx <= n { self.ary[idx - 1] += val.clone(); idx += idx & idx.wrapping_neg(); } } /// Returns data[l] + ... + data[r - 1]. pub fn sum(&self, l: usize, r: usize) -> T where T: std::ops::Sub<Output = T>, { self.accum(r) - self.accum(l) } } #[cfg(test)] mod tests { use super::*; #[test] fn fenwick_tree_works() { let mut bit = FenwickTree::new(5, 0i64); // [1, 2, 3, 4, 5] for i in 0..5 { bit.add(i, i as i64 + 1); } assert_eq!(bit.sum(0, 5), 15); assert_eq!(bit.sum(0, 4), 10); assert_eq!(bit.sum(1, 3), 5); } } } use fenwicktree::*; fn main() { solve(); } fn solve() { let mut ans: u64 = 0; let N = get!(usize); let s = get!(String) .chars() .map(|x| { x.to_lowercase() .to_string() .chars() .next() .unwrap() .toAlphabetIndex() }) .toVec(); mydbg!(s); let mut a = vec![FenwickTree::new(N, 0_i32); 26]; for i in 0..N { let t = s[i]; a[t].add(i, 1); } let mut agct = ['a', 'g', 'c', 't'] .iter() .map(|&x| x.toAlphabetIndex()) .toVec(); let mut L = 0; let mut count = FenwickTree::new(N, 0_i32); for i in 0..N { count.add(i, 1); } loop { let mut c1 = 0; for &item in &agct { c1 += a[item].accum(N); } if c1 == 0 { break; } let mut l = -1; let mut r = N as i32; while l + 1 != r { let m = (l + r) / 2; if count.accum((m + 1) as usize) < c1 { l = m; } else { r = m; } } let mut c1_index = r as usize; let mut c2 = 0; for i in 0..26 { let k = a[i].accum(c1_index + 1) - a[i].accum(c1_index); if k == 1 { a[i].add(c1_index, -1); c2 = a[i].accum(N) as usize; count.add(c1_index, -1); break; } } for i in 0..4 { agct[i] += 26 * 100000; agct[i] -= c2; agct[i] %= 26; } ans += 1; } echo!(ans); }