1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

初心者プログラマーAtCoderに挑んだ軌跡-ABC414-A-

Last updated at Posted at 2025-09-03

ABC414-A

問題の内容

配列の中身と比較

言語

Rust

解法

2次元配列をインプットしてif文で条件に合う場合のみcount++

課題

  • 二次元配列の書き方・input

学んだこと

  • a[[i32; w];h],//h行w列の二次元配列
  • usizeとi32,i64の違い
    usize → 正の整数かつ添え字やサイズ※計算には使わない
    i32 → 小さい整数(cの32bit int)
    i64 → デカい整数(i32でオーバーフローするときに使う)
    大は小を兼ねるためi64にしておくと安全
  • Rustでは++は使えない…

提出内容

use proconio::input;

fn main() {
  input! {
    n: usize,
    l: i64,
    r: i64,
    s: [[i64; 2]; n],
  }
  let mut count = 0;
  for i in &s { //借用するとこう書けるらしい。勉強になるねぇ
      if i[0] <= l && i[1] >= r {
      count += 1;
      }
  }
  println!("{}", count);
}

ちなみにイテレータを使うとfor文の部分が

let count = s.iter()//前から順に
    .filter(|i| i[0] <= l && i[1] >= r)//条件フィルター
    .count();//数え上げ

ってできるそうです。

成績

  • 318Byte
  • AC
  • 1ms
  • 2072KiB

iter使用の方

  • 279Byte
  • AC
  • 1ms
  • 2088KiB
    コード長は短くなったけどメモリは多めに食う。ただ、可読性が段違い。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?