結果
| 問題 |
No.1279 Array Battle
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-11-06 21:25:59 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 1,907 bytes |
| コンパイル時間 | 11,882 ms |
| コンパイル使用メモリ | 384,460 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 12:05:46 |
| 合計ジャッジ時間 | 12,836 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#![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
}
}
fukafukatani