結果

問題 No.1279 Array Battle
ユーザー fukafukatanifukafukatani
提出日時 2020-11-06 21:25:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,907 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 154,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 18:06:17
合計ジャッジ時間 1,956 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 27 ms
4,376 KB
testcase_19 AC 19 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let b = read_vec::<i64>();

    let mut p = Permutation::new(n);
    let mut count = BTreeMap::new();
    loop {
        let mut temp = 0;
        for i in 0..n {
            temp += max(a[p.indexes[i]] - b[i], 0);
        }
        *count.entry(temp).or_insert(0) += 1;
        if !p.next_permutation() {
            break;
        }
    }

    println!("{}", count.values().rev().next().unwrap());
}

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 read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
struct Permutation {
    indexes: Vec<usize>,
}

impl Permutation {
    fn new(n: usize) -> Permutation {
        Permutation {
            indexes: (0..n).collect::<Vec<_>>(),
        }
    }

    fn next_permutation(&mut self) -> bool {
        if self.indexes.len() < 2 {
            return false;
        }

        let mut i = self.indexes.len() - 1;
        while i > 0 && self.indexes[i - 1] >= self.indexes[i] {
            i -= 1;
        }

        if i == 0 {
            return false;
        }

        let mut j = self.indexes.len() - 1;
        while j >= i && self.indexes[j] <= self.indexes[i - 1] {
            j -= 1;
        }

        self.indexes.swap(j, i - 1);
        self.indexes[i..].reverse();
        true
    }
}
0