結果

問題 No.2055 12x34...
ユーザー titia
提出日時 2022-08-25 01:43:33
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 15,531 ms
コンパイル使用メモリ 396,260 KB
実行使用メモリ 10,524 KB
最終ジャッジ日時 2024-10-12 09:38:20
合計ジャッジ時間 16,899 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `A` should have a snake case name
  --> src/main.rs:10:9
   |
10 |     let A: Vec<i64> = {
   |         ^ help: convert the identifier to snake case: `a`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: variable `DP` should have a snake case name
  --> src/main.rs:21:13
   |
21 |     let mut DP: BTreeMap<i64, i64> = BTreeMap::new();
   |             ^^ help: convert the identifier to snake case: `dp`

ソースコード

diff #

use std::collections::BTreeMap;

fn main() {
    let n: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let modx = 998244353;
    let mut ans=0;

    let mut DP: BTreeMap<i64, i64> = BTreeMap::new();

    for i in 0..n{
        let a=A[i];

        let mut x=0;

        if DP.contains_key(&(a-1)){
            x=DP[&(a-1)];
        }

        ans=(ans+x)%modx;

        if DP.contains_key(&(a)){
            DP.insert(a,(DP[&(a)]+x+1)%modx);
        }
        else{
            DP.insert(a,(x+1)%modx);
        }
    }

    println!("{}",ans);
}
0