Submission #73689472


Source Code Expand

use proconio::input;

fn main() {
    input! {
        s: String,
        t: String,
    }

    let s_chars: Vec<char> = s.chars().collect();
    let t_chars: Vec<char> = t.chars().collect();

    let s_no_a: Vec<char> = s_chars.iter().copied().filter(|&c| c != 'A').collect();
    let t_no_a: Vec<char> = t_chars.iter().copied().filter(|&c| c != 'A').collect();

    if s_no_a != t_no_a {
        println!("-1");
        return;
    }

    let get_a_segments = |chars: &[char]| -> Vec<usize> {
        let mut counts = Vec::new();
        let mut current_count = 0;
        for &c in chars {
            if c == 'A' {
                current_count += 1;
            } else {
                counts.push(current_count);
                current_count = 0;
            }
        }
        counts.push(current_count);
        counts
    };

    let s_a_counts = get_a_segments(&s_chars);
    let t_a_counts = get_a_segments(&t_chars);

    // 各セグメントの 'A' の数の差の絶対値を合計
    let ans: i64 = s_a_counts
        .iter()
        .zip(t_a_counts.iter())
        .map(|(&s, &t)| (s as i64 - t as i64).abs())
        .sum();

    println!("{}", ans);
}

Submission Info

Submission Time
Task C - Insert and Erase A
User memoka
Language Rust (rustc 1.89.0)
Score 300
Code Size 1221 Byte
Status AC
Exec Time 9 ms
Memory 12344 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2064 KiB
00_sample_01.txt AC 1 ms 1872 KiB
00_sample_02.txt AC 1 ms 1900 KiB
00_sample_03.txt AC 1 ms 1796 KiB
01_random_00.txt AC 1 ms 3292 KiB
01_random_01.txt AC 2 ms 4348 KiB
01_random_02.txt AC 5 ms 7464 KiB
02_random2_00.txt AC 5 ms 8984 KiB
02_random2_01.txt AC 5 ms 5664 KiB
02_random2_02.txt AC 8 ms 11344 KiB
02_random2_03.txt AC 9 ms 10664 KiB
02_random2_04.txt AC 7 ms 8540 KiB
02_random2_05.txt AC 4 ms 5596 KiB
02_random2_06.txt AC 7 ms 9728 KiB
02_random2_07.txt AC 3 ms 4716 KiB
02_random2_08.txt AC 7 ms 6616 KiB
02_random2_09.txt AC 8 ms 7788 KiB
02_random2_10.txt AC 7 ms 9988 KiB
02_random2_11.txt AC 8 ms 11236 KiB
03_random3_00.txt AC 5 ms 7480 KiB
03_random3_01.txt AC 4 ms 5256 KiB
03_random3_02.txt AC 4 ms 6444 KiB
03_random3_03.txt AC 5 ms 6116 KiB
04_handmade_00.txt AC 1 ms 1912 KiB
04_handmade_01.txt AC 1 ms 1896 KiB
04_handmade_02.txt AC 1 ms 1792 KiB
04_handmade_03.txt AC 1 ms 1824 KiB
04_handmade_04.txt AC 7 ms 12344 KiB
04_handmade_05.txt AC 4 ms 6556 KiB
04_handmade_06.txt AC 4 ms 6576 KiB
04_handmade_07.txt AC 4 ms 5444 KiB
04_handmade_08.txt AC 2 ms 3708 KiB
04_handmade_09.txt AC 2 ms 3592 KiB