結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-30 19:54:27 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,484 bytes |
| コンパイル時間 | 15,519 ms |
| コンパイル使用メモリ | 378,760 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 08:25:02 |
| 合計ジャッジ時間 | 14,429 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#[macro_export]
macro_rules! setup {
{ mut $input:ident: SplitWhitespace $(,)? } => {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut $input = buf.split_whitespace();
};
}
#[macro_export]
macro_rules! parse_next {
($str_iter:expr) => {
$str_iter.next().unwrap().parse().ok().unwrap()
};
}
use std::collections::HashMap;
fn main() {
setup! { mut input: SplitWhitespace };
let n: usize = parse_next!(input);
let m: usize = parse_next!(input);
let mut board = HashMap::new();
(0..m).for_each(|_| {
let i: usize = parse_next!(input);
let j: usize = parse_next!(input);
let s: usize = parse_next!(input);
board.insert((i, j), s);
});
let ans = (|| {
let mut dp = vec![0; 1 << n];
for src in 0..(1 << n) {
for i in 0..n {
if (src >> i) & 1 == 0 {
let mut score = dp[src];
for j in 0..n {
if (src >> j) & 1 == 1 {
if let Some(s) = board.get(&(i, j)) {
score += s;
}
}
}
let dest = src | (1 << i);
dp[dest] = dp[dest].max(score);
}
}
}
dp[(1 << n) - 1]
})();
println!("{}", ans);
}