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 3 years have passed since last update.

[AtCoder] ABC 202 C - Made Up

Posted at

$1 \le n \le N$の整数 $n$ に対して、$A_{i} = n$ となる $A_{i}$ の個数を数え上げます。
同様に $n$ に対して $B_{C_{j}} = n$ も数え上げます。
同じ $n$ に対する $A_{i}$ の個数と $B_{C_{j}}$ の個数を掛け合わせて組み合わせ $(i, j)$ が求められます。
それを全ての $n$ に対して計算すると答えが求められます。
言語はC++(GCC 9.2.1)でAtCoderのコードテストで確認しています。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll N, a, ans = 0;
  cin >> N;
  vector<ll> A(N, 0), B(N, 0), C(N, 0), D(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> a;
    A[a-1]++;
  }
  for (ll i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (ll i = 0; i < N; i++) {
    cin >> C[i];
  }
  for (ll i = 0; i < N; i++) {
    D[B[C[i]-1]-1]++;
  }
  for (ll i = 0; i < N; i++) {
    ans += A[i] * D[i];
  }
  cout << ans << endl;
}
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?