結果
| 問題 |
No.437 cwwゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-05 19:40:44 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,700 bytes |
| コンパイル時間 | 14,285 ms |
| コンパイル使用メモリ | 403,100 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 08:38:26 |
| 合計ジャッジ時間 | 15,652 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
コンパイルメッセージ
warning: unused macro definition: `parse_input`
--> src/main.rs:3:14
|
3 | macro_rules! parse_input {
| ^^^^^^^^^^^
|
= note: `#[warn(unused_macros)]` on by default
warning: unused macro definition: `parse_inputs`
--> src/main.rs:7:14
|
7 | macro_rules! parse_inputs {
| ^^^^^^^^^^^^
warning: unused macro definition: `print_err`
--> src/main.rs:16:14
|
16 | macro_rules! print_err {
| ^^^^^^^^^
ソースコード
use std::io;
macro_rules! parse_input {
($x:expr, $t:ident) => ($x.trim().parse::<$t>().unwrap())
}
macro_rules! parse_inputs {
($x:expr, $t:ident) => (
$x.trim()
.split_whitespace()
.map(|s| s.parse::<$t>().unwrap())
.collect::<Vec<$t>>()
)
}
macro_rules! print_err {
($($arg:tt)*) => (
{
use std::io::Write;
writeln!(&mut ::std::io::stderr(), $($arg)*).ok();
}
)
}
fn cww(a: i64, b: i64, c: i64) -> i64 {
let mut x = -1;
if a != 0 && a != b && b == c {
x = a * 100 + b * 10 + c;
}
x
}
fn main() {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let s = input_line.trim().bytes().map(|x| (x as i64) - 48).collect::<Vec<i64>>();
let n = s.len();
let mut dp = vec![-1; 1 << n];
dp[0] = 0;
for state in 0..(1 << n) {
if dp[state] == -1 {
continue;
}
for i in 0..n {
for j in (i + 1)..n {
for k in (j + 1)..n {
if ((state >> i) & 1) | ((state >> j) & 1) | ((state >> k) & 1) != 0 {
continue;
}
let x = cww(s[i], s[j], s[k]);
if x != -1 {
let nxstate = state | (1 << i) | (1 << j) | (1 << k);
if dp[nxstate] < dp[state] + x {
dp[nxstate] = dp[state] + x
} else {
dp[nxstate] = dp[nxstate]
};
}
}
}
}
}
println!("{}", dp.iter().max().unwrap());
}