結果
問題 | No.2226 Hello, Forgotten World! |
ユーザー | rp523 |
提出日時 | 2023-02-24 21:51:42 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 11,257 bytes |
コンパイル時間 | 16,532 ms |
コンパイル使用メモリ | 405,604 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 05:22:40 |
合計ジャッジ時間 | 13,225 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
ソースコード
#![allow(unused_macros, unused_imports, dead_code)] use std::any::TypeId; use std::cmp::{max, min, Reverse}; use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; use std::mem::swap; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign}; mod my_string { use std::ops::{Index, IndexMut}; use std::slice::SliceIndex; #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] pub struct Str { vc: Vec<char>, } impl Str { pub fn new() -> Self { Self { vc: vec![] } } pub fn from(s: &str) -> Self { Self { vc: s.to_string().chars().collect::<Vec<char>>(), } } pub fn len(&self) -> usize { self.vc.len() } pub fn clear(&mut self) { self.vc.clear() } pub fn is_empty(&self) -> bool { self.vc.is_empty() } pub fn first(&self) -> Option<&char> { self.vc.first() } pub fn last(&self) -> Option<&char> { self.vc.last() } pub fn push(&mut self, c: char) { self.vc.push(c); } pub fn push_str(&mut self, s: &str) { for c in s.to_string().chars().collect::<Vec<char>>().into_iter() { self.push(c); } } pub fn pop(&mut self) -> Option<char> { self.vc.pop() } pub fn into_iter(self) -> std::vec::IntoIter<char> { self.vc.into_iter() } pub fn iter(&self) -> std::slice::Iter<char> { self.vc.iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut<char> { self.vc.iter_mut() } pub fn swap(&mut self, a: usize, b: usize) { self.vc.swap(a, b); } pub fn reverse(&mut self) { self.vc.reverse(); } pub fn find(&self, p: &Str) -> Option<usize> { let s: String = self.vc.iter().collect::<String>(); let p: String = p.vc.iter().collect::<String>(); s.find(&p) } pub fn rfind(&self, p: &Str) -> Option<usize> { let s: String = self.vc.iter().collect::<String>(); let p: String = p.vc.iter().collect::<String>(); s.rfind(&p) } pub fn into_values(self, base: char) -> Vec<usize> { self.vc .into_iter() .map(|c| (c as u8 - base as u8) as usize) .collect::<Vec<usize>>() } pub fn sort(&mut self) { self.vc.sort(); } pub fn remove(&mut self, index: usize) -> char { self.vc.remove(index) } } impl std::str::FromStr for Str { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(Str { vc: s.to_string().chars().collect::<Vec<char>>(), }) } } impl<Idx: SliceIndex<[char]>> Index<Idx> for Str { type Output = Idx::Output; fn index(&self, i: Idx) -> &Self::Output { &self.vc[i] } } impl<Idx: SliceIndex<[char]>> IndexMut<Idx> for Str { fn index_mut(&mut self, index: Idx) -> &mut Self::Output { &mut self.vc[index] } } impl std::ops::Add<Str> for Str { type Output = Str; fn add(self, rhs: Self) -> Self::Output { let mut ret = self; for c in rhs.into_iter() { ret.vc.push(c); } ret } } impl std::ops::AddAssign<Str> for Str { fn add_assign(&mut self, rhs: Self) { for c in rhs.into_iter() { self.vc.push(c); } } } impl std::ops::Add<char> for Str { type Output = Str; fn add(self, rhs: char) -> Self::Output { let mut ret = self; ret.vc.push(rhs); ret } } impl std::ops::AddAssign<char> for Str { fn add_assign(&mut self, rhs: char) { self.vc.push(rhs); } } impl std::fmt::Display for Str { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.vc.iter().collect::<String>()) } } impl std::fmt::Debug for Str { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.vc.iter().collect::<String>()) } } } use my_string::Str; mod procon_reader { use std::fmt::Debug; use std::io::Read; use std::str::FromStr; pub fn read<T: FromStr>() -> T where <T as FromStr>::Err: Debug, { let stdin = std::io::stdin(); let mut stdin_lock = stdin.lock(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin_lock.read(&mut u8b); if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { break; } else { buf.push(u8b[0]); } } if !buf.is_empty() { let ret = String::from_utf8(buf).unwrap(); return ret.parse().unwrap(); } } } pub fn read_vec<T: std::str::FromStr>(n: usize) -> Vec<T> where <T as FromStr>::Err: Debug, { (0..n).into_iter().map(|_| read::<T>()).collect::<Vec<T>>() } pub fn read_vec_sub1(n: usize) -> Vec<usize> { (0..n) .into_iter() .map(|_| read::<usize>() - 1) .collect::<Vec<usize>>() } pub fn read_mat<T: std::str::FromStr>(h: usize, w: usize) -> Vec<Vec<T>> where <T as FromStr>::Err: Debug, { (0..h) .into_iter() .map(|_| read_vec::<T>(w)) .collect::<Vec<Vec<T>>>() } } use procon_reader::*; fn exit_by<T: std::fmt::Display>(msg: T) { println!("{}", msg); std::process::exit(0); } mod gcd { use std::cmp::{PartialEq, PartialOrd}; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign}; pub fn gcd<T: Copy + Sub<Output = T> + Rem<Output = T> + PartialEq>(a: T, b: T) -> T { #[allow(clippy::eq_op)] let zero = a - a; if b == zero { a } else { gcd(b, a % b) } } // returns (p, q) s. t. ap + bq = gcd(a, b) pub fn ext_gcd< T: Eq + Copy + Sub<Output = T> + SubAssign + Mul<Output = T> + Div<Output = T> + Rem<Output = T>, >( a: T, b: T, ) -> (T, T) { #[allow(clippy::eq_op)] let zero = b - b; #[allow(clippy::eq_op)] let one = b / b; if a == zero { return (zero, one); } // (b % a) * x + a * y = gcd(a, b) // b % a = b - (b / a) * a // -> // (b - (b / a) * a) * x + a * y = gcd(a, b) // a * (y - (b / a) * x) + b * x = gcd(a, b) let (x, y) = ext_gcd(b % a, a); (y - b / a * x, x) } // Chinese Remainder Theorem // when exists, returns (lcm(m1, m2), x) s.t. x = r1 (mod m1) and x = r2 (mod m2) fn chinese_rem_elem2< T: Eq + Copy + Neg<Output = T> + PartialOrd + Add<Output = T> + AddAssign + Sub<Output = T> + SubAssign + Mul<Output = T> + Div<Output = T> + Rem<Output = T> + RemAssign, >( m1: T, r1: T, m2: T, r2: T, ) -> Option<(T, T)> { #[allow(clippy::eq_op)] let zero = m1 - m1; #[allow(clippy::eq_op)] let one = m1 / m1; let (p, _q) = ext_gcd(m1, m2); let g = gcd(m1, m2); if (r2 - r1) % g != zero { None } else { let lcm = m1 * (m2 / g); let mut r = r1 + m1 * ((r2 - r1) / g) * p; if r < zero { let dv = (-r + lcm - one) / lcm; r += dv * lcm; } r %= lcm; Some((lcm, r)) } } // Chinese Remainder Theorem // when exists, returns (lcm(mods), x) s.t. x = r_i (mod m_i) for all i. pub fn chinese_rem< T: Eq + Copy + Neg<Output = T> + PartialOrd + Add<Output = T> + AddAssign + Sub<Output = T> + SubAssign + Mul<Output = T> + Div<Output = T> + Rem<Output = T> + RemAssign, >( mods: &[T], rems: &[T], ) -> Option<(T, T)> { debug_assert!(mods.len() == rems.len()); #[allow(clippy::eq_op)] let zero = mods[0] - mods[0]; #[allow(clippy::eq_op)] let one = mods[0] / mods[0]; let mut lcm = one; let mut rem = zero; for (m, r) in mods.iter().copied().zip(rems.iter().copied()) { if let Some((nlcm, nrem)) = chinese_rem_elem2(lcm, rem, m, r) { lcm = nlcm; rem = nrem; } else { return None; } } Some((lcm, rem)) } } use gcd::*; mod power_with_identity { use std::ops::Mul; pub fn power_with_identity<T: Copy + Mul<Output = T>>(identity: T, base: T, mut p: usize) -> T { #[allow(clippy::eq_op)] let mut ret = identity; let mut mul = base; while p > 0 { if p & 1 != 0 { ret = ret * mul; } p >>= 1; mul = mul * mul; } ret } } use power_with_identity::power_with_identity; /************************************************************************************* *************************************************************************************/ fn main() { fn solve() -> Str { let n = read::<usize>(); let s = read::<Str>(); let t = Str::from("helloworld"); for i in (0..n).rev() { if i + t.len() - 1 > n - 1 { continue; } let mut can = true; for ti in 0..t.len() { let j = i + ti; if s[j] == '?' { continue; } if s[j] == t[ti] { continue; } can = false; break; } if can { let mut ans = Str::new(); for j in 0..n { if (i <= j) && (j < i + t.len()) { ans.push(t[j - i]); } else if s[j] == '?' { ans.push('a'); } else { ans.push(s[j]); } } return ans; } } Str::from("-1") } let mut ans = vec![]; for _ in 0..read::<usize>() { ans.push(solve()); } for ans in ans { println!{"{}", ans}; } }