Submission #516846

#TimeUsernameProblemLanguageResultExecution timeMemory
516846Marslai24Set (COCI21_set)C++17
40 / 110
1076 ms37616 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long // a.k.a. TLE creator
#define all(x) x.begin(), x.end()
template<class A, class B> istream& operator >>(istream &o, pair<A, B> &x){return o >> x.first >> x.second;}
template<class A, class B> ostream& operator <<(ostream &o, pair<A, B> &x){return o << x.first << ' ' << x.second << ' ';}
void setIO(){ios::sync_with_stdio(false); cin.tie(0);}
const int INF = INT_MAX, MOD = 998244353, N = 1e6, K = __lg(N) + 1;

signed main(){
    setIO();
    int n, k;
    cin >> n >> k;
    int pw[k + 1]{1};
    for(int i = 1; i <= k; i++)pw[i] = pw[i - 1] * 10;
    vector<int> s(n);
    for(auto &i : s)cin >> i;
    map<int, int> cnt;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int now = 0, x = s[i], y = s[j];
            for(int l = 0; l < k; l++, x /= 10, y /= 10){
                if(x % 10 == y % 10)now += x % 10 * pw[l];
                else{
                    for(int c = 1; c <= 3; c++){
                        if(x % 10 != c && y % 10 != c)now += c * pw[l];
                    }
                }
            }
            cnt[now]++;
        }
    }
    int ans = 0;
    for(auto i : s){
        ans += cnt[i];
    }
    cout << ans / 3;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...