結果
| 問題 | No.1279 Array Battle | 
| コンテスト | |
| ユーザー |  Strorkis | 
| 提出日時 | 2020-11-06 21:35:24 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 1,884 bytes | 
| コンパイル時間 | 15,457 ms | 
| コンパイル使用メモリ | 379,204 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-22 12:21:29 | 
| 合計ジャッジ時間 | 14,388 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
pub mod procon_input {
    use std::{str::FromStr, iter::FromIterator};
    pub fn read_line() -> String {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).ok();
        input
    }
    pub fn parse<T: FromStr>(s: &str) -> T {
        s.parse().ok().unwrap()
    }
    
    pub fn read<T: FromStr>() -> T {
        parse(read_line().trim_end())
    }
    
    pub fn read_collection<T: FromStr, C: FromIterator<T>>() -> C {
        read_line().split_whitespace().map(parse).collect()
    }
    #[macro_export]
    macro_rules! read_tuple {
        ( $( $t:ty ),* ) => {{
            let input = read_line();
            let mut iter = input.split_whitespace();
            ( $( parse::<$t>(iter.next().unwrap()) ),* )
        }};
    }
}
use procon_input::*;
use std::cmp::max;
use std::collections::VecDeque;
fn dfs(a: &mut VecDeque<i32>, b: &mut VecDeque<i32>) -> (i32, usize) {
    if a.len() == 0 { return (0, 1) }
    let (mut max_point, mut max_count) = (0, 0);
    let bi = b.pop_front().unwrap();
    for _ in 0..a.len() {
        let ai = a.pop_front().unwrap();
        let (mut point, count) = dfs(a, b);
        point += max(0, ai - bi);
        a.push_back(ai);
        if max_point < point {
            max_point = point;
            max_count = count;
        } else if max_point == point {
            max_count += count;
        }
    }
    b.push_front(bi);
    (max_point, max_count)
}
fn solve(writer: &mut std::io::BufWriter<std::io::StdoutLock>) {
    use std::io::Write;
    let _n: usize = read();
    let mut a: VecDeque<i32> = read_collection();
    let mut b: VecDeque<i32> = read_collection();
    let (_, ans) = dfs(&mut a, &mut b);
    writeln!(writer, "{}", ans).ok();
}
fn main() {
    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());
    solve(&mut writer);
}
            
            
            
        