Submission #1240858

#TimeUsernameProblemLanguageResultExecution timeMemory
1240858eirinayukariPIN (CEOI10_pin)C++20
30 / 100
80 ms34376 KiB
// XD XD
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el cout << "\n";

using namespace std;
using ll = long long;

const int MAXN = 1e6 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e18 + 7;

template <typename T>
bool ckmin(T& a, T b) {
    return a > b ? a = b, true : false;
}

template <typename T>
bool ckmax(T& a, T b) {
    return a < b ? a = b, true : false;
}

ll get(string s) {
    ll res = 0;
    for (char x : s) {
        res *= 36;
        if (isdigit(x)) {
            res += x - '0';
        } else {
            res += x - 'a' + 10;
        }
    }
    return res;
}   

int n, d;
string s[MAXN];
ll calc(int mask) {
    map<ll, int> mp;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        string sub = "";
        for (int j = 0; j < 4; j++) {
            if (mask >> j & 1) {
                sub += s[i][j];
            }
        }
        ll val = get(sub);
        res += mp[val]++;
    }
    return res;
}

void solve(int id) {
    // cout << "Case " << id << ": ";
    cin >> n >> d;
    d = 4 - d;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    ll ans = 0;
    for (int mask = 0; mask < (1 << 4); mask++) {
        int cm = __builtin_popcount(mask);
        if (cm == d) {
            ans += calc(mask);
        } 
        if (cm == d + 1) {
            ans -= calc(mask);
        }
    }
    cout << ans << "\n";
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        solve(i);
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...