結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー akakimidoriakakimidori
提出日時 2019-08-30 22:15:48
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,595 bytes
コンパイル時間 3,074 ms
コンパイル使用メモリ 153,012 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 06:58:05
合計ジャッジ時間 3,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut dp = vec![0; n + 1];
    for i in 1..=n {
        let mut s = i;
        let mut j = 1;
        while j * j <= i {
            s = std::cmp::min(s, dp[i - j * j] + j);
            j += 1;
        }
        dp[i] = s;
    }
    let mut a = vec![];
    let mut m = n;
    while m > 0 {
        let mut find = false;
        let mut j = 1;
        while j * j <= m && !find {
            if dp[m - j * j] + j == dp[m] {
                find = true;
                m -= j * j;
                a.push(j);
            }
            j += 2;
        }
        let mut j = 2;
        while j * j <= m && !find {
            if dp[m - j * j] + j == dp[m] {
                find = true;
                m -= j * j;
                a.push(j);
            }
            j += 2;
        }
    }
    a.sort_by(|a, b| {
        if a % 2 == b % 2 {
            a.cmp(&b)
        } else if a % 2 == 1 {
            std::cmp::Ordering::Less
        } else {
            std::cmp::Ordering::Greater
        }
    });
    let mut ans = String::new();
    let mut prev = '0';
    for mut a in a {
        ans.push(prev);
        a -= 1;
        while a > 1 {
            ans.push(if prev == '1' {'0'} else {'1'});
            ans.push(prev);
            a -= 2;
        }
        if a > 0 {
            ans.push(if prev == '1' {'0'} else {'1'});
            prev = if prev == '1' {'0'} else {'1'};
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}
0