結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー phsplsphspls
提出日時 2022-12-07 23:30:28
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 160,568 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 03:51:03
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 265 ms
5,376 KB
testcase_03 AC 214 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 52 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 0 ms
5,376 KB
testcase_32 AC 7 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 32 ms
5,376 KB
testcase_35 AC 276 ms
5,376 KB
testcase_36 AC 138 ms
5,376 KB
testcase_37 AC 278 ms
5,376 KB
testcase_38 AC 280 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{collections::BinaryHeap, cmp::Reverse};

const INF: usize = 1usize << 60;

fn priority(val: usize) -> usize {
    if val % 2 == 1 {
        val
    } else {
        INF - val
    }
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let mut dp = vec![INF; n+1];
    dp[0] = 0;
    for i in 1..=n {
        for j in 1..=i {
            let val = j * j;
            if val > i { break; }
            dp[i] = dp[i].min(dp[i-val] + j);
        }
    }
    let mut result = String::new();
    let mut target = n;
    while target > 0 {
        let mut pque = BinaryHeap::new();
        for i in 1..=target {
            let val = i * i;
            if val > target { break; }
            if dp[target-val] + i == dp[target] {
                pque.push((Reverse(priority(i)), i));
            }
        }
        let (_, i) = pque.pop().unwrap();
        let val = if i % 2 == 1 { format!("0{}", "10".repeat(i/2)) } else { format!("{}", if result.ends_with('1') { "10".repeat(i/2) } else { "01".repeat(i/2) }) };
        result.push_str(&val);
        target -= i * i;
    }
    println!("{}", result);
}
0