提出 #5091528


ソースコード 拡げる

//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let S = rl().chars().collect::<Vec<_>>();

    // 境界
    let mut k = 0;
    // 境界より左側にある黒の個数
    let mut left_black = 0;
    // 境界より右側にある白の個数
    let mut right_white = S.iter().filter(|&&c| c == '.').count();

    let mut min_cost = N;

    while k <= N {
        min_cost = min(min_cost, left_black + right_white);

        // 境界を右に動かす。
        if k < N && S[k] == '#' {
            left_black += 1;
        }
        if k < N && S[k] == '.' {
            right_white -= 1;
        }
        k += 1;
    }

    println!("{}", min_cost)
}

提出情報

提出日時
問題 C - Stones
ユーザ vain0
言語 Rust (1.15.1)
得点 300
コード長 2614 Byte
結果 AC
実行時間 3 ms
メモリ 4352 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 25
セット名 テストケース
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt, s3.txt
ケース名 結果 実行時間 メモリ
01.txt AC 3 ms 4352 KiB
02.txt AC 3 ms 4352 KiB
03.txt AC 3 ms 4352 KiB
04.txt AC 3 ms 4352 KiB
05.txt AC 3 ms 4352 KiB
06.txt AC 3 ms 4352 KiB
07.txt AC 3 ms 4352 KiB
08.txt AC 3 ms 4352 KiB
09.txt AC 3 ms 4352 KiB
10.txt AC 3 ms 4352 KiB
11.txt AC 3 ms 4352 KiB
12.txt AC 3 ms 4352 KiB
13.txt AC 3 ms 4352 KiB
14.txt AC 3 ms 4352 KiB
15.txt AC 3 ms 4352 KiB
16.txt AC 3 ms 4352 KiB
17.txt AC 3 ms 4352 KiB
18.txt AC 3 ms 4352 KiB
19.txt AC 2 ms 4352 KiB
20.txt AC 2 ms 4352 KiB
21.txt AC 2 ms 4352 KiB
22.txt AC 2 ms 4352 KiB
s1.txt AC 2 ms 4352 KiB
s2.txt AC 2 ms 4352 KiB
s3.txt AC 2 ms 4352 KiB