第2回早稲田大学プログラミングコンテスト

Submission #1754922

Source codeソースコード

fn main() {
  let n: usize = get::val();
  let s = get::chars();
  
  let mut dp = vec![0; n];
  for i in 0 .. 3 {
    if s[i] == 'X' {dp[i] = 1}
  }
  for i in 3 .. n {
    let d = if s[i] == 'X' {1} else {0};
    dp[i] = [dp[i-3], dp[i-2], dp[i-1]].iter().min().unwrap() + d
  }

  println!("{}", dp[n-1])
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}

Submission

Task問題 B - 雨上がり
User nameユーザ名 aimy
Created time投稿日時
Language言語 Rust (1.15.1)
Status状態 AC
Score得点 50
Source lengthソースコード長 2492 Byte
File nameファイル名
Exec time実行時間 2 ms
Memory usageメモリ使用量 4352 KB

Test case

Set

Set name Score得点 / Max score Cases
All 50 / 50 case_000.txt,case_001.txt,case_002.txt,case_003.txt,case_004.txt,case_005.txt,case_006.txt,case_007.txt,case_008.txt,case_009.txt,case_010.txt,case_011.txt,case_012.txt,case_013.txt,case_014.txt,case_015.txt,case_016.txt,case_017.txt,case_018.txt,case_019.txt,case_020.txt,case_021.txt,case_022.txt,case_023.txt,case_024.txt,case_025.txt,case_026.txt,case_027.txt,case_028.txt,case_029.txt,case_030.txt,case_031.txt,case_032.txt,case_033.txt,case_034.txt,case_035.txt,case_036.txt,case_037.txt,case_038.txt,case_039.txt,case_040.txt,case_041.txt,case_042.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
case_000.txt AC 2 ms 4352 KB
case_001.txt AC 2 ms 4352 KB
case_002.txt AC 2 ms 4352 KB
case_003.txt AC 2 ms 4352 KB
case_004.txt AC 2 ms 4352 KB
case_005.txt AC 2 ms 4352 KB
case_006.txt AC 2 ms 4352 KB
case_007.txt AC 2 ms 4352 KB
case_008.txt AC 2 ms 4352 KB
case_009.txt AC 2 ms 4352 KB
case_010.txt AC 2 ms 4352 KB
case_011.txt AC 2 ms 4352 KB
case_012.txt AC 2 ms 4352 KB
case_013.txt AC 2 ms 4352 KB
case_014.txt AC 2 ms 4352 KB
case_015.txt AC 2 ms 4352 KB
case_016.txt AC 2 ms 4352 KB
case_017.txt AC 2 ms 4352 KB
case_018.txt AC 2 ms 4352 KB
case_019.txt AC 2 ms 4352 KB
case_020.txt AC 2 ms 4352 KB
case_021.txt AC 2 ms 4352 KB
case_022.txt AC 2 ms 4352 KB
case_023.txt AC 2 ms 4352 KB
case_024.txt AC 2 ms 4352 KB
case_025.txt AC 2 ms 4352 KB
case_026.txt AC 2 ms 4352 KB
case_027.txt AC 2 ms 4352 KB
case_028.txt AC 2 ms 4352 KB
case_029.txt AC 2 ms 4352 KB
case_030.txt AC 2 ms 4352 KB
case_031.txt AC 2 ms 4352 KB
case_032.txt AC 2 ms 4352 KB
case_033.txt AC 2 ms 4352 KB
case_034.txt AC 2 ms 4352 KB
case_035.txt AC 2 ms 4352 KB
case_036.txt AC 2 ms 4352 KB
case_037.txt AC 2 ms 4352 KB
case_038.txt AC 2 ms 4352 KB
case_039.txt AC 2 ms 4352 KB
case_040.txt AC 2 ms 4352 KB
case_041.txt AC 2 ms 4352 KB
case_042.txt AC 2 ms 4352 KB