Submission #63035314


Source Code Expand

Copy
#[derive_readable]
#[derive(Debug, Clone)]
struct Problem {
xs: Chars,
}
impl Problem {
fn read() -> Problem {
input! {
p: Problem,
}
p
}
fn solve(&self) -> Answer {
let mut xs = self.xs.clone();
let rle = xs.iter().copied().dedup_with_count().collect_vec();
let n = xs.len();
let mut ans = vec![];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#[derive_readable]
#[derive(Debug, Clone)]
struct Problem {
    xs: Chars,
}

impl Problem {
    fn read() -> Problem {
        input! {
            p: Problem,
        }
        p
    }

    fn solve(&self) -> Answer {
        let mut xs = self.xs.clone();
        let rle = xs.iter().copied().dedup_with_count().collect_vec();
        let n = xs.len();

        let mut ans = vec![];

        let mut i = 0;

        while i < rle.len() {
            if i < rle.len() - 1 && rle[i].1 == 'W' && rle[i + 1].1 == 'A' {
                // WWWWA → ACCCC
                ans.push('A');
                for _ in 0..rle[i].0 {
                    ans.push('C');
                }

                for _ in 0..(rle[i + 1].0 - 1) {
                    ans.push('A');
                }

                i += 2;
            } else {
                for _ in 0..rle[i].0 {
                    ans.push(rle[i].1);
                }
                i += 1;
            }
        }

        Answer { ans }
    }

    #[allow(dead_code)]
    fn solve_naive(&self) -> Answer {
        todo!();
        // let ans = 0;
        // Answer { ans }
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
struct Answer {
    ans: Vec<char>,
}

impl Answer {
    fn print(&self) {
        print_chars(&self.ans);
    }
}

fn main() {
    Problem::read().solve().print();
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;
    #[allow(unused_imports)]
    use rand::{rngs::SmallRng, seq::SliceRandom, *};

    #[test]
    fn test_problem() {
        assert_eq!(1 + 1, 2);
    }

    #[allow(dead_code)]
    #[derive(Debug)]
    struct WrongTestCase {
        problem: Problem,
        main_ans: Answer,
        naive_ans: Answer,
    }

    #[allow(dead_code)]
    fn check(p: &Problem) -> Option<WrongTestCase> {
        let main_ans = p.solve();
        let naive_ans = p.solve_naive();
        if main_ans != naive_ans {
            Some(WrongTestCase {
                problem: p.clone(),
                main_ans,
                naive_ans,
            })
        } else {
            None
        }
    }

    #[allow(dead_code)]
    fn make_random_problem(rng: &mut SmallRng) -> Problem {
        todo!()
        // let n = rng.gen_range(1..=10);
        // let p = Problem { _a: n };
        // println!("{:?}", &p);
        // p
    }

    #[allow(unreachable_code)]
    #[test]
    fn test_with_naive() {
        let num_tests = 0;
        let max_wrong_case = 10; // この件数間違いが見つかったら打ち切り
        let mut rng = SmallRng::seed_from_u64(42);
        // let mut rng = SmallRng::from_entropy();
        let mut wrong_cases: Vec<WrongTestCase> = vec![];
        for _ in 0..num_tests {
            let p = make_random_problem(&mut rng);
            let result = check(&p);
            if let Some(wrong_test_case) = result {
                wrong_cases.push(wrong_test_case);
            }
            if wrong_cases.len() >= max_wrong_case {
                break;
            }
        }

        if !wrong_cases.is_empty() {
            for t in &wrong_cases {
                println!("{:?}", t.problem);
                println!("main ans : {:?}", t.main_ans);
                println!("naive ans: {:?}", t.naive_ans);
                println!();
            }
            println!("{} cases are wrong.", wrong_cases.len());
            panic!();
        }
    }
}

// ====== import ======
#[allow(unused_imports)]
use itertools::{chain, iproduct, izip, Itertools};
#[allow(unused_imports)]
use proconio::{
    derive_readable, fastout, input,
    marker::{Bytes, Chars, Usize1},
};
#[allow(unused_imports)]
use std::cmp::Reverse;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

// ====== output func ======
#[allow(unused_imports)]
use print_vec::*;
pub mod print_vec {

    use itertools::Itertools;
    use proconio::fastout;
    #[fastout]
    pub fn print_vec<T: std::fmt::Display>(arr: &[T]) {
        for a in arr {
            println!("{}", a);
        }
    }
    #[fastout]
    pub fn print_vec_1line<T: std::fmt::Display>(arr: &[T]) {
        let msg = arr.iter().map(|x| format!("{}", x)).join(" ");
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec2<T: std::fmt::Display>(arr: &Vec<Vec<T>>) {
        for row in arr {
            let msg = row.iter().map(|x| format!("{}", x)).join(" ");
            println!("{}", msg);
        }
    }
    pub fn print_bytes(bytes: &[u8]) {
        let msg = String::from_utf8(bytes.to_vec()).unwrap();
        println!("{}", msg);
    }
    pub fn print_chars(chars: &[char]) {
        let msg = chars.iter().collect::<String>();
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec_bytes(vec_bytes: &[Vec<u8>]) {
        for row in vec_bytes {
            let msg = String::from_utf8(row.to_vec()).unwrap();
            println!("{}", msg);
        }
    }
}

#[allow(unused)]
fn print_yesno(ans: bool) {
    let msg = if ans { "Yes" } else { "No" };
    println!("{}", msg);
}

// ====== snippet ======

Submission Info

Submission Time
Task C - Debug
User paruma184
Language Rust (rustc 1.70.0)
Score 300
Code Size 5065 Byte
Status AC
Exec Time 5 ms
Memory 6516 KB

Compile Error

warning: unused variable: `n`
  --> src/main.rs:18:13
   |
18 |         let n = xs.len();
   |             ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> src/main.rs:16:13
   |
16 |         let mut xs = self.xs.clone();
   |             ----^^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 1860 KB
example_01.txt AC 1 ms 1916 KB
example_02.txt AC 1 ms 1868 KB
hand_00.txt AC 4 ms 5676 KB
hand_01.txt AC 5 ms 5652 KB
hand_02.txt AC 4 ms 5448 KB
hand_03.txt AC 4 ms 5724 KB
hand_04.txt AC 1 ms 1920 KB
hand_05.txt AC 1 ms 2016 KB
hand_06.txt AC 4 ms 5628 KB
random_00.txt AC 5 ms 6516 KB
random_01.txt AC 5 ms 6484 KB
random_02.txt AC 4 ms 5672 KB
random_03.txt AC 4 ms 5580 KB
random_04.txt AC 4 ms 5704 KB
random_05.txt AC 4 ms 5600 KB
random_06.txt AC 4 ms 5636 KB
random_07.txt AC 4 ms 5620 KB
random_08.txt AC 4 ms 5648 KB
random_09.txt AC 4 ms 5588 KB
random_10.txt AC 4 ms 5516 KB
random_11.txt AC 4 ms 5664 KB
random_12.txt AC 4 ms 5712 KB
random_13.txt AC 4 ms 5560 KB
random_14.txt AC 4 ms 5672 KB
random_15.txt AC 4 ms 5644 KB
random_16.txt AC 5 ms 5444 KB
random_17.txt AC 4 ms 5520 KB
random_18.txt AC 4 ms 5568 KB
random_19.txt AC 4 ms 5712 KB


2025-04-11 (Fri)
10:14:12 +00:00