結果

問題 No.2094 Symmetry
ユーザー akakimidoriakakimidori
提出日時 2022-10-07 22:15:48
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,707 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 158,080 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2023-09-03 13:07:12
合計ジャッジ時間 6,243 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 95 ms
13,720 KB
testcase_10 AC 95 ms
13,676 KB
testcase_11 AC 95 ms
13,728 KB
testcase_12 AC 95 ms
13,676 KB
testcase_13 AC 96 ms
13,728 KB
testcase_14 AC 95 ms
13,728 KB
testcase_15 AC 96 ms
13,720 KB
testcase_16 AC 95 ms
13,732 KB
testcase_17 WA -
testcase_18 AC 96 ms
13,712 KB
testcase_19 AC 96 ms
13,728 KB
testcase_20 AC 97 ms
13,716 KB
testcase_21 AC 96 ms
13,720 KB
testcase_22 AC 95 ms
13,680 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 94 ms
13,728 KB
testcase_26 AC 95 ms
13,724 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 26 ms
12,324 KB
testcase_32 AC 26 ms
12,400 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 31 ms
12,152 KB
testcase_35 AC 38 ms
11,608 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run() {
    input! {
        n: usize,
        k: i64,
        s: [bytes; 2 * n],
        c: [[i64; 2 * n]; 2 * n],
    }
    let black = s.iter().flatten().filter(|c| **c == b'#').count();
    let mut ord = vec![];
    for i in 0..(2 * n) {
        for j in 0..(2 * n) {
            ord.push((i, j));
        }
    }
    ord.sort_by_key(|p| -c[p.0][p.1]);
    let mut a = vec![vec![false; 2 * n]; 2 * n];
    let mut sum = 0;
    for p in ord.iter().take(black) {
        a[p.0][p.1] = true;
        sum += c[p.0][p.1];
    }
    let mut ans = std::i64::MIN;
    if a.iter().all(|a| a.iter().zip(a.iter().rev()).all(|a| a.0 == a.1)) {
        ans = ans.max(sum + k);
        if ord.len() > black {
            for &(sign, p) in [(-1, ord[black - 1]), (1, ord[black])].iter() {
                sum += sign * c[p.0][p.1];
            }
            ans = ans.max(sum);
        }
    } else {
        ans = ans.max(sum);
        let mut ord = vec![];
        for i in 0..(2 * n) {
            for j in 0..n {
                ord.push(c[i][j] + c[i][2 * n - 1 - j]);
            }
        }
        ord.sort();
        ans = ans.max(k + ord.iter().rev().take(black / 2).sum::<i64>());
    }
    println!("{}", ans);
}

fn main() {
    run();
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
0