제출 #1240861

#제출 시각아이디문제언어결과실행 시간메모리
1240861eirinayukariPIN (CEOI10_pin)C++20
100 / 100
99 ms34880 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 C[5][5] = {
        {1, 0, 0, 0, 0},
        {1, 1, 0, 0, 0},
        {1, 2, 1, 0, 0},
        {1, 3, 3, 1, 0},
        {1, 4, 6, 4, 1}
    };

    ll ans = 0;
    for (int mask = 0; mask < (1 << 4); mask++) {
        int k = __builtin_popcount(mask);
        if (k < d) continue;
        ll cnt  = calc(mask);
        ll sign = ((k - d) & 1) ? -1 : 1;
        ans += sign * C[k][d] * cnt;
    }

    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...