Submission #136829

#TimeUsernameProblemLanguageResultExecution timeMemory
136829choikiwonPIN (CEOI10_pin)C++17
60 / 100
378 ms16504 KiB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 50010;

int N, D;
string pin[maxn];
int bcnt[16];
map<string, int> cnt[16];

int main() {
    std::ios::sync_with_stdio(false);

    for(int i = 0; i < 16; i++) {
        for(int j = 0; j < 4; j++) if(i & (1 << j)) bcnt[i]++;
    }

    cin >> N >> D;
    D = 4 - D;

    for(int i = 0; i < N; i++) {
        cin >> pin[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 16; j++) {
            string tmp;
            for(int k = 0; k < 4; k++) {
                if(j & (1 << k)) tmp.push_back(pin[i][k]);
                else tmp.push_back(' ');
            }
            cnt[j][tmp]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < 16; i++) {
        if(bcnt[i] < D) continue;

        for(auto it = cnt[i].begin(); it != cnt[i].end(); it++) {
            if((bcnt[i] - D) % 2) ans -= 1LL * it->second * (it->second - 1) / 2;
            else ans += 1LL * it->second * (it->second - 1) / 2;
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...