結果

問題 No.2247 01 ZigZag
ユーザー ssssssss
提出日時 2023-05-21 16:50:33
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,624 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 150,592 KB
実行使用メモリ 10,472 KB
最終ジャッジ日時 2023-08-23 15:12:32
合計ジャッジ時間 3,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 10 ms
7,644 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,620 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 8 ms
6,648 KB
testcase_09 AC 9 ms
7,560 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 5 ms
4,732 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 13 ms
10,080 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 8 ms
6,248 KB
testcase_23 AC 5 ms
4,604 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 8 ms
6,432 KB
testcase_26 AC 6 ms
5,024 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 11 ms
8,404 KB
testcase_29 AC 12 ms
9,028 KB
testcase_30 AC 10 ms
8,268 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 5 ms
4,376 KB
testcase_39 WA -
testcase_40 AC 9 ms
7,420 KB
testcase_41 WA -
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 13 ms
10,460 KB
testcase_46 AC 13 ms
10,472 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 WA -
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;
#[allow(unused_imports)]
use std::{io::Write, cmp};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read() -> usize {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().unwrap()
}

#[allow(non_snake_case)]
fn main() {
    input! { n: usize, m: usize, k:usize }

    let mut n = n;
    let mut m = m;
    let mut nn: VecDeque<Vec<char>> = VecDeque::new();
    let mut mm: VecDeque<Vec<char>> = VecDeque::new();

    let mut hanten = false;
    // 0 1 0 1
    if n <= k/2+1 {
        let tmp = n;
        n = m;
        m = tmp;
        hanten = true;
    }

    if n + m < k {
        return println!("-1");
    }
    if k == 0 {
        if n == 0 {
            return println!("{}", "1".to_string().repeat(m));
        }
        if m == 0 {
            return println!("{}", "1".to_string().repeat(n));
        }
        return println!("-1");
    }

    for kk in 0..=k  {
        if kk % 2 == 0 {
            if n > 0 {
                nn.push_back(vec!['0']);
                n -= 1;
            } else {
                return println!("-1");
            }
        } else {
            if m > 0 {
                mm.push_back(vec!['1']);
                m -= 1;
            } else {
                return println!("-1");
            }
        }
    }

    // println!("nokori n {} m {}", n, m);

    while n > 0 {
        let tmp: &mut Vec<char> = nn.front_mut().unwrap();
        tmp.push('0');
        n -= 1;
    }
    while m > 0 {
        let tmp: &mut Vec<char> = mm.back_mut().unwrap();
        tmp.push('1');
        m -= 1;
    }
    // println!("nn {:?} mm {:?}", nn, mm);
    let mut ans = VecDeque::new();

    while !nn.is_empty() || !mm.is_empty() {
        if !nn.is_empty() {
            let tmp_n = nn.pop_front().unwrap();
            ans.push_back(tmp_n);
        }
        if !mm.is_empty() {
            let tmp_m = mm.pop_front().unwrap();
            ans.push_back(tmp_m);
        }
    }
    if hanten {
        let tmp = ans.iter().flatten().collect::<String>();
        tmp.chars().for_each(|c| if c == '0' { print!("1") } else { print!("0") });
        println!("");
    } else {
        println!("{}", ans.iter().flatten().collect::<String>());
    }
}
0