結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー akakimidoriakakimidori
提出日時 2019-08-30 22:57:44
言語 Rust
(1.72.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,021 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 151,576 KB
実行使用メモリ 6,620 KB
最終ジャッジ日時 2023-09-06 07:03:36
合計ジャッジ時間 5,471 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 184 ms
4,564 KB
testcase_01 WA -
testcase_02 AC 415 ms
6,340 KB
testcase_03 AC 332 ms
5,824 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 79 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 47 ms
4,376 KB
testcase_35 AC 438 ms
6,620 KB
testcase_36 AC 214 ms
4,772 KB
testcase_37 AC 429 ms
6,552 KB
testcase_38 AC 436 ms
6,604 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, 0); n + 1];
    for i in 1..=n {
        let mut s = dp[i - 1];
        s.0 += 1;
        s.1 += 1;
        let mut j = 2;
        while j * j <= i {
            let v = dp[i - j * j];
            if s.0 > v.0 + j {
                s = v;
                s.0 += j;
            } else if s.0 == v.0 + j && s.1 < v.1 {
                s = v;
                s.0 += j;
            }
            j += 1;
        }
        dp[i] = s;
    }
    let mut a = vec![];
    let mut m = n;
    while m > 0 {
        if dp[m].1 > 0 {
            a.push(1);
            m -= 1;
            continue;
        }
        let mut find = false;
        let mut j = 3;
        while j * j <= m && !find{
            if dp[m - j * j].0 + j == dp[m].0 {
                find = true;
                m -= j * j;
                a.push(j);
            }
            j += 2;
        }
        let mut j = 2;
        while j * j <= m && !find {
            if dp[m - j * j].0 + j == dp[m].0 {
                find = true;
                m -= j * j;
                a.push(j);
            }
            j += 2;
        }
    }
    a.sort_by(|a, b| {
        if a % 2 == b % 2 {
            if a % 2 == 1 {
                a.cmp(&b)
            } else {
                b.cmp(&a)
            }
        } 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