公式

B - Mapping 解説 by en_translator


Let us first review the questions. Let \(S\) be the set of types of clothes worn, \(F_1, F_2, \dots, F_N\), without duplicates. Then:

  • Question \(1\) asks whether \(|S| = N\), and
  • Question \(2\) asks whether \(|S| = M\),

where \(|S|\) denotes the size of the set. Therefore, the problem can be solved by finding the size of \(S\).
Most programming languages have a data structure that handles sets. For example, C++ has std::set type, and Python has set type, which facilitates the implementation.

  • Sample code (C++)
#include <iostream>
#include <set>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  set<int> S;
  for (int i = 0; i < N; i++) {
    int F;
    cin >> F;
    S.insert(F);
  }
  cout << ((int)S.size() == N ? "Yes" : "No") << "\n";
  cout << ((int)S.size() == M ? "Yes" : "No") << "\n";
}

投稿日時:
最終更新: