結果

問題 No.2601 Very Poor
ユーザー 👑 H20H20
提出日時 2024-01-12 22:49:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 185,488 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-03-20 19:49:24
合計ジャッジ時間 2,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 0 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 17 ms
8,064 KB
testcase_16 AC 18 ms
8,064 KB
testcase_17 AC 17 ms
8,064 KB
testcase_18 AC 17 ms
8,064 KB
testcase_19 AC 17 ms
8,064 KB
testcase_20 AC 17 ms
8,064 KB
testcase_21 AC 17 ms
8,064 KB
testcase_22 AC 17 ms
8,064 KB
testcase_23 AC 17 ms
8,064 KB
testcase_24 AC 18 ms
8,064 KB
testcase_25 AC 17 ms
8,064 KB
testcase_26 AC 17 ms
8,064 KB
testcase_27 AC 17 ms
8,064 KB
testcase_28 AC 18 ms
8,064 KB
testcase_29 AC 17 ms
8,064 KB
testcase_30 AC 17 ms
8,064 KB
testcase_31 AC 17 ms
8,064 KB
testcase_32 AC 17 ms
8,064 KB
testcase_33 AC 17 ms
8,064 KB
testcase_34 AC 18 ms
8,064 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:19:9
   |
19 |     let mut a: Vec<usize> = input
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::collections::VecDeque;
use std::io;
use std::str::FromStr;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let parts: Vec<usize> = input
        .trim()
        .split_whitespace()
        .map(|x| usize::from_str(x).unwrap())
        .collect();

    let n = parts[0];
    let _x = parts[1];

    input.clear();
    io::stdin().read_line(&mut input).unwrap();
    let mut a: Vec<usize> = input
        .trim()
        .split_whitespace()
        .map(|x| usize::from_str(x).unwrap())
        .collect();

    // Aを連結する
    let mut extended_a = a.clone();
    extended_a.extend(a);

    // Dequeの作成
    let mut deque = VecDeque::new();
    let mut total = 0;
    let mut ans = 0;

    for &item in &extended_a {
        deque.push_back(item);
        total += item;

        // 合計がxを超えたら先頭から要素を取り出す
        while total > _x || deque.len() > n{
            if let Some(front) = deque.pop_front() {
                total -= front;
            }
        }
        ans = std::cmp::max(ans,total);
    }

    // 最終的なDequeの内容を表示
    println!("{}", ans);
}
0