結果

問題 No.2623 Room Allocation
ユーザー naut3naut3
提出日時 2024-02-09 22:34:50
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,202 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 187,112 KB
実行使用メモリ 17,480 KB
最終ジャッジ日時 2024-02-09 22:34:53
合計ジャッジ時間 2,828 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 0 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 WA -
testcase_06 AC 15 ms
7,424 KB
testcase_07 WA -
testcase_08 AC 15 ms
8,320 KB
testcase_09 WA -
testcase_10 AC 10 ms
9,416 KB
testcase_11 WA -
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 5 ms
6,676 KB
testcase_14 WA -
testcase_15 AC 17 ms
6,676 KB
testcase_16 WA -
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 17 ms
6,676 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 17 ms
6,676 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 18 ms
6,676 KB
testcase_25 WA -
testcase_26 AC 3 ms
6,676 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case, unused_imports, unused_must_use)]
use std::io::{self, prelude::*};
use std::str;

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    macro_rules! input {
        ($T: ty) => {
            scan.token::<$T>()
        };
        ($T: ty, $N: expr) => {
            (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>()
        };
    }

    let N = input!(usize);
    let X = input!(usize);
    let Y = input!(usize);

    let mut P = vec![];
    let mut C = vec![];

    for _ in 0..N {
        let (p, c) = (input!(usize), input!(char));
        P.push(p);
        C.push(c);
    }

    let mut A = vec![0; X + Y];
    let mut B = vec![0; X + Y];

    for i in 0..N {
        let (p, c) = (P[i], C[i]);

        if c == 'A' {
            A[i % (X + Y)] += p;
        } else {
            B[i % (X + Y)] += p;
        }
    }

    let mut vals = vec![];
    let mut ans = 0;

    for i in 0..X + Y {
        let (a, b) = (A[i], B[i]);

        let m = std::cmp::min(a, b);
        ans += m;
        vals.push((a - m, b - m));
    }

    vals.sort();
    vals.reverse();

    for i in 0..X {
        ans += vals[i].0;
    }

    for i in X..X + Y {
        ans += vals[i].1;
    }

    writeln!(out, "{}", ans);
}

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}
0