Submission #1864742


Source Code Expand

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            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();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}


fn shorten(ab: (usize, usize)) -> (usize, usize) {
    if ab.0 > ab.1 {
        let t = ab.0 - ab.1;
        match t % 3 {
            2 => (0, 1),
            x => (x, 0),
        }
    } else {
        let t = ab.1 - ab.0;
        match t % 3 {
            2 => (1, 0),
            x => (0, x),
        }
    }
}

fn main() {
    let s = util::line();
    let t = util::line();

    let mut accs = vec![(0, 0)];
    let mut acct = vec![(0, 0)];

    let q = get!(usize);

    let mut acc = (0, 0);
    for c in s.chars() {
        if c == 'A' {
            acc.0 += 1;
        } else {
            acc.1 += 1;
        }

        accs.push(acc);
    }

    let mut acc = (0, 0);
    for c in t.chars() {
        if c == 'A' {
            acc.0 += 1;
        } else {
            acc.1 += 1;
        }

        acct.push(acc);
    }

    for _ in 0..q {
        let (a, b, c, d) = get!(usize, usize, usize, usize);
        let ls = accs[a - 1];
        let rs = accs[b];

        let lt = acct[c - 1];
        let rt = acct[d];

        if shorten((rs.0 - ls.0, rs.1 - ls.1)) == shorten((rt.0 - lt.0, rt.1 - lt.1)) {
            println!("YES");
        } else {
            println!("NO");
        }
    }

}

Submission Info

Submission Time
Task E - TrBBnsformBBtion
User hatoo
Language Rust (1.15.1)
Score 600
Code Size 3431 Byte
Status AC
Exec Time 212 ms
Memory 8700 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 16
Set Name Test Cases
Sample 0_000.txt, 0_001.txt
All 0_000.txt, 0_001.txt, bound_0.txt, bound_1.txt, bound_2.txt, bound_3.txt, min.txt, rnd_10000_10.txt, rnd_10000_10000.txt, rnd_10000_2.txt, rnd_10_10.txt, rnd_10_10000.txt, rnd_10_2.txt, rnd_2_10.txt, rnd_2_10000.txt, rnd_2_2.txt
Case Name Status Exec Time Memory
0_000.txt AC 2 ms 4352 KB
0_001.txt AC 2 ms 4352 KB
bound_0.txt AC 195 ms 8700 KB
bound_1.txt AC 194 ms 8700 KB
bound_2.txt AC 212 ms 8700 KB
bound_3.txt AC 199 ms 8700 KB
min.txt AC 2 ms 4352 KB
rnd_10000_10.txt AC 194 ms 8700 KB
rnd_10000_10000.txt AC 199 ms 8700 KB
rnd_10000_2.txt AC 200 ms 8700 KB
rnd_10_10.txt AC 198 ms 8700 KB
rnd_10_10000.txt AC 193 ms 8700 KB
rnd_10_2.txt AC 200 ms 8700 KB
rnd_2_10.txt AC 194 ms 8700 KB
rnd_2_10000.txt AC 204 ms 8700 KB
rnd_2_2.txt AC 194 ms 8700 KB