0
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?

More than 1 year has passed since last update.

paizaラーニング レベルアップ問題集 線形探索メニュー応用編 JavaScript ピクニック

Posted at

ピクニック (paizaランク B 相当)

解答例

レジャーシートを敷ける場所の数countを用意します。
山を二次元配列にします。
レジャーシート左上を基準に、山の区画を順に、平行か調べます。

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf-8").trim();
const lines = input.split("\n");

const [n, m] = lines[0].split(" ").map(Number);

let count = 0;//敷ける場所の数
//山を二次元配列に
const mountain = lines.slice(1).map(line => line.split(" ").map(Number));

//レジャーシート左上を基準に、山の区画を順に、平行か調べる。
for (let i = 0; i < n - 1; i++) { //レジャーシートは2mなのでn-1
  for (let j = 0; j < m - 1; j++) { //同様にmー1
    //平行ならば
    if (mountain[i][j] === mountain[i + 1][j] &&
        mountain[i + 1][j] === mountain[i][j + 1] &&
        mountain[i][j + 1] === mountain[i + 1][j + 1] ) 
    {
      count += 1;//カウントする
    }
  }
}
console.log(count);
0
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
0
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?