結果

問題 No.3044 April Sum of Odd
ユーザー kenichikenichi
提出日時 2023-03-23 18:22:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,428 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 177,136 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 19:35:07
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::*;
//use std::num;
use std::str::FromStr;
//use std::time::Instant;

fn main() {
    //let now = Instant::now();
    let n: usize = read();
    let m: usize = read();
    let mut a = vec![0; n];
    let mut ans: u64 = 0;
    let mut flag_start: usize = 0;
    let mut flag_end: usize;
    let mut flag_move: bool = false;

    for _i in 0..a.len() {
        a[_i] = read();
    } 

    for _i in 0..n{
        if n == 1 && a[0] % 2 == 1{
            println!("{}",a[0]);
        }else if flag_move == false && a[_i] % 2 == 1{
            flag_start = _i;
            flag_move = true;
        }else if flag_move == true && a[_i] % 2 == 1{
            if _i >= n-1{
                for _j in flag_start..n{
                    ans += a[_j];
                }
                println!("{}",ans);
                ans = 0;
            }
        }else if flag_move == false && a[_i] % 2 == 0{

        }else if flag_move == true && a[_i] % 2 == 0{
            flag_end = _i;
            if flag_end - flag_start >= m{
                for _j in flag_start..flag_end{
                    ans += a[_j];
                }
                println!("{}",ans);
                ans = 0;
            }
            flag_move = false;
        }
    }

    //println!("[DEBUG_PRINT] {} ms", now.elapsed().as_millis());
}

pub fn min(x: usize, y: usize) -> usize {
    let z: usize;

    if x <= y {
        z = x;
    } else {
        z = y;
    }

    return z;
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_array() -> Vec<char> {
    let array: String = read();
    let chars: Vec<char> = array.trim().chars().collect::<Vec<char>>();
    chars
}

pub fn get_data() -> Vec<u64> {
    let mut s: String = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec: Vec<u64> = s
        .trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();

    vec
}

pub fn get_chars() -> Vec<char> {
    let mut s: String = String::new();
    std::io::stdin().read_line(&mut s).ok();

    let vec: Vec<char> = s.trim().chars().collect::<Vec<char>>();

    vec
}
0