AT_abc348_f [ABC348F] Oddly Similar tj

· · 题解

思路

根据题意模拟,n^2 搜索两个数列进行判断是否为相似序列即可。最后在 atcoder 上使用 C++23(clang++) 提交便跑得飞快。

Code

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;
const int E = 1e6 + 5;
ll n, m;
ll a[2005][2005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    ll ans = 0, cnt;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
        {
            cnt = 0;
            for (int k = 1; k <= m; k++)
                if (a[i][k] == a[j][k])
                    cnt++;
            ans += ((cnt & 1) == 1);
        }
    cout << ans;
    return 0;
}