Official

C - Couples Editorial by en_translator


By mathematically interpreting the problem statement, it turns out that it is asking to count \(i\) such that \(A_i=A_{i+2}\).

Use for and if statements to check if each \(i\) satisfies the condition.

Sample code (C++):

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n * 2);
  for(auto &v : a) cin >> v;
  int res = 0;
  for(int i = 0; i < n * 2 - 2; i++)
    if(a[i] == a[i + 2]) res++;
  cout << res << endl;
}

posted:
last update: