작성일 :

문제 링크

31995번 - 게임말 올려놓기

설명

N×M 격자에서 서로 대각선으로 이웃한 두 칸에 말을 놓는 경우의 수를 구하는 문제입니다.


접근법

2×2 블록마다 대각선 쌍이 2개 존재합니다.
따라서 경우의 수는 2 * (N-1) * (M-1)입니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
using System;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var m = int.Parse(Console.ReadLine()!);
    var ans = 2 * (n - 1) * (m - 1);
    Console.WriteLine(ans);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  int m; cin >> m;
  int ans = 2 * (n - 1) * (m - 1);
  cout << ans << "\n";

  return 0;
}