Submission #31286258


Source Code Expand

Copy
use proconio::input;
fn main() {
input! {
mut n: i64,
};
let mut ans = vec![];
let mut sum = 0_i64;
for x in 0.. {
if n - sum == 0 {
break;
}
let r = (n - sum) % 2_i64.pow(x + 1);
if r != 0 {
ans.push(1);
sum += (-2_i64).pow(x);
} else {
ans.push(0);
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
use proconio::input;

fn main() {
    input! {
        mut n: i64,
    };

    let mut ans = vec![];
    let mut sum = 0_i64;
    for x in 0.. {
        if n - sum == 0 {
            break;
        }
        let r = (n - sum) % 2_i64.pow(x + 1);
        if r != 0 {
            ans.push(1);
            sum += (-2_i64).pow(x);
        } else {
            ans.push(0);
        }
    }
    if ans.is_empty() {
        ans.push(0);
    }
    ans.reverse();
    println!(
        "{}",
        ans.into_iter()
            .map(|i| (b'0' + i as u8) as char)
            .collect::<String>()
    );
}

Submission Info

Submission Time
Task C - Base -2 Number
User bouzuya
Language Rust (1.42.0)
Score 300
Code Size 596 Byte
Status AC
Exec Time 7 ms
Memory 2160 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All 0_small0, 0_small1, 0_small2, 0_small3, 0_small4, 1_large0, 1_large1, 1_large2, 1_large3, 1_large4, 1_large5, 1_large6, 1_large7, 2_max0, 2_max1, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_small0 AC 7 ms 2008 KB
0_small1 AC 1 ms 2024 KB
0_small2 AC 2 ms 2052 KB
0_small3 AC 1 ms 2040 KB
0_small4 AC 2 ms 2060 KB
1_large0 AC 1 ms 2152 KB
1_large1 AC 1 ms 1980 KB
1_large2 AC 2 ms 2036 KB
1_large3 AC 2 ms 2112 KB
1_large4 AC 1 ms 2160 KB
1_large5 AC 2 ms 2092 KB
1_large6 AC 2 ms 2076 KB
1_large7 AC 1 ms 2108 KB
2_max0 AC 2 ms 2120 KB
2_max1 AC 1 ms 2012 KB
sample_01 AC 1 ms 2108 KB
sample_02 AC 1 ms 2144 KB
sample_03 AC 3 ms 2128 KB


2025-04-11 (Fri)
13:21:56 +00:00