結果

問題 No.1313 N言っちゃダメゲーム (4)
ユーザー koba-e964koba-e964
提出日時 2021-11-04 12:57:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,778 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 171,612 KB
実行使用メモリ 6,028 KB
最終ジャッジ日時 2024-04-22 11:29:05
合計ジャッジ時間 2,279 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 5 ms
5,852 KB
testcase_14 AC 5 ms
6,028 KB
testcase_15 AC 6 ms
5,944 KB
testcase_16 AC 6 ms
5,844 KB
testcase_17 AC 6 ms
5,852 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 6 ms
5,844 KB
testcase_29 AC 6 ms
5,848 KB
testcase_30 AC 7 ms
5,720 KB
testcase_31 AC 6 ms
5,844 KB
testcase_32 AC 6 ms
5,844 KB
testcase_33 AC 5 ms
5,852 KB
testcase_34 AC 6 ms
5,976 KB
testcase_35 AC 5 ms
5,848 KB
testcase_36 AC 5 ms
5,852 KB
testcase_37 AC 5 ms
5,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize, k: usize,
        s: chars,
    }
    let mut acc = vec![0; n + 1];
    let mut dp = vec![0; n];
    for i in (0..n).rev() {
        if i > 0 && s[i - 1] == 'x' {
            dp[i] = 1;
        } else {
            let hi = min(n, i + k + 1);
            dp[i] = if acc[i + 1] - acc[hi] == hi - i - 1 {
                0
            } else {
                1
            };
        }
        acc[i] = acc[i + 1] + dp[i];
    }
    if dp[0] == 0 {
        puts!("0\n");
    } else {
        for i in 1..k + 1 {
            if dp[i] == 0 {
                puts!("{}\n", i);
            }
        }
    }
}
0