結果

問題 No.2247 01 ZigZag
ユーザー ssssssss
提出日時 2023-05-21 16:21:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,237 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 151,848 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-08-23 15:11:04
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 10 ms
7,636 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 5 ms
4,612 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 8 ms
6,668 KB
testcase_09 AC 10 ms
7,460 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,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 13 ms
10,120 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 8 ms
6,280 KB
testcase_23 AC 5 ms
4,544 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 9 ms
6,436 KB
testcase_26 AC 6 ms
4,988 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 10 ms
8,336 KB
testcase_29 AC 11 ms
9,080 KB
testcase_30 AC 10 ms
8,260 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 4 ms
4,380 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 9 ms
7,444 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 13 ms
10,400 KB
testcase_46 AC 13 ms
10,400 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,376 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();

    if k == 0 {
        if n == 0 {
            return println!("{}", "1".to_string().repeat(m));
        }
        if m == 0 {
            return println!("{}", "0".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);
        }
    }
    let ret = ans.iter().flatten().collect::<String>();
    println!("{}", ret);
}
0