結果

問題 No.1537 私の代わりに仕事やっといてください。
ユーザー 57tggx57tggx
提出日時 2021-05-22 17:32:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 2,788 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 158,416 KB
実行使用メモリ 17,116 KB
最終ジャッジ日時 2023-08-17 18:36:25
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 61 ms
17,116 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),* $(,)*) => {
        #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}

#[derive(Debug)]
struct Input {
    n: usize,
    a: Vec<i64>,
}

fn main() {
    let Input { n, a } = Input::read(std::io::stdin().lock());

    let mut v: Vec<_> = a.into_iter().enumerate().collect();

    v.sort_by(|(_, x), (_, y)| x.cmp(y));

    let v: Vec<_> = v.into_iter().map(|(i, _)| i + 1).collect();

    println!(
        "{}",
        v.iter()
            .chain(v.iter().rev())
            .chain(v.iter())
            .skip_while(|&&x| x != 1)
            .step_by(2)
            .take(n + 1)
            .map(ToString::to_string)
            .collect::<Vec<_>>()
            .join(" ")
    );
}

/* 入力の厳密な受け取り
 * フォーマットのチェック
 * 制約のチェック */
impl Input {
    fn read<T: std::io::BufRead>(mut input: T) -> Input {
        let n = {
            let mut buffer = String::new();
            input.read_line(&mut buffer).unwrap();
            match &split(&buffer).unwrap()[..] {
                &[n] => n.parse().unwrap(),
                _ => panic!("input format error: N"),
            }
        };
        let a: Vec<i64> = {
            let mut buffer = String::new();
            input.read_line(&mut buffer).unwrap();
            split(&buffer)
                .unwrap()
                .into_iter()
                .map(|x| x.parse().unwrap())
                .collect()
        };

        assert!(matches!(n, 2..=200_000));
        assert_eq!(n, a.len());
        assert!(a.iter().all(|x| matches!(x, 1..=1_000_000_000)));

        Input { n: n, a: a }
    }
}

fn split(s: &str) -> Option<Vec<&str>> {
    enum State {
        Word(usize),
        Space,
        End,
    }
    let mut state = State::Word(0);
    let mut ret = Vec::new();
    for (i, c) in s.char_indices() {
        let prev = match state {
            State::End => return None,
            State::Word(i) => i,
            State::Space => {
                state = State::Word(i);
                i
            }
        };
        if c == ' ' || c == '\n' {
            ret.push(&s[prev..i]);
            state = if c == ' ' { State::Space } else { State::End };
        }
    }
    matches!(state, State::End).then(|| ret)
}

#[test]
fn test_split() {
    assert_eq!(split("word\n"), Some(vec!["word"]));
    assert_eq!(
        split("many words separated\n"),
        Some(vec!["many", "words", "separated"])
    );
    assert_eq!(
        split(" extra  spaces \n"),
        Some(vec!["", "extra", "", "spaces", ""])
    );
    assert_eq!(split("no line feed"), None);
    assert_eq!(split("extra characters\nafter line feed"), None);
}
0