Submission #58991107


Source Code Expand

#![allow(unused)]

fn main() {
    let inp = readv::<usize>();
    let (n, q) = (inp[0], inp[1]);
    let mut pos_l = 0 as usize;
    let mut pos_r = 1 as usize;
    let mut ans = 0;

    for _ in 0..q {
        let ask = readv::<String>();
        let h = ask[0].chars().next().unwrap();
        let t = ask[1].parse::<usize>().unwrap() - 1;
        if h == 'L' {
            let (src, dst) = (pos_l.min(t), pos_l.max(t));
            // d1 = dst - src, d2 = n - d1
            if src <= pos_r && pos_r <= dst {
                ans += n - (dst - src);
            } else {
                ans += dst - src;
            }
            pos_l = t;
        } else {
            let (src, dst) = (pos_r.min(t), pos_r.max(t));
            // d1 = dst - src, d2 = n - d1
            if src <= pos_l && pos_l <= dst {
                ans += n - (dst - src);
            } else {
                ans += dst - src;
            }
            pos_r = t;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn readv<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_ascii_whitespace()
        .map(|t| t.parse().ok().unwrap())
        .collect()
}

fn reads() -> Vec<char> {
    read::<String>().chars().collect()
}

fn mapv<T, S, F: Fn(&T) -> S>(arr: &Vec<T>, f: F) -> Vec<S> {
    arr.iter().map(f).collect()
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

Submission Info

Submission Time
Task B - Hands on Ring (Easy)
User amoshuangyc
Language Rust (rustc 1.70.0)
Score 250
Code Size 1688 Byte
Status AC
Exec Time 1 ms
Memory 2072 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 3
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 0 ms 1780 KiB
00_sample_01.txt AC 0 ms 1928 KiB
00_sample_02.txt AC 0 ms 2064 KiB
01_random_00.txt AC 0 ms 2072 KiB
01_random_01.txt AC 0 ms 1988 KiB
01_random_02.txt AC 0 ms 1920 KiB
01_random_03.txt AC 0 ms 1924 KiB
01_random_04.txt AC 0 ms 1920 KiB
01_random_05.txt AC 0 ms 1920 KiB
01_random_06.txt AC 1 ms 1976 KiB
01_random_07.txt AC 1 ms 1916 KiB
01_random_08.txt AC 0 ms 2068 KiB
01_random_09.txt AC 0 ms 1856 KiB
01_random_10.txt AC 0 ms 1960 KiB
01_random_11.txt AC 0 ms 1908 KiB
01_random_12.txt AC 0 ms 2048 KiB
01_random_13.txt AC 0 ms 1788 KiB
01_random_14.txt AC 0 ms 1720 KiB
01_random_15.txt AC 0 ms 1920 KiB
02_handmade_00.txt AC 0 ms 1932 KiB
02_handmade_01.txt AC 0 ms 1780 KiB
02_handmade_02.txt AC 0 ms 1960 KiB
02_handmade_03.txt AC 0 ms 1912 KiB
02_handmade_04.txt AC 0 ms 2048 KiB