Submission #742616

# Submission time Handle Problem Language Result Execution time Memory
742616 2023-05-16T15:30:14 Z ducanh1234 PIN (CEOI10_pin) C++14
100 / 100
296 ms 14812 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int K = 4;
const int N = 5e4+1;
 
map<string, ll> mp[(1<<K)];
 
ll ans[6], n, d;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    cin>>n>>d;
    for (int i=1; i<=n; ++i) {
        string s; cin>>s;
 
        for (int j=0; j<(1<<K); ++j) {
            string tmp="";
            for (int x=0; x<K; ++x) {
                if (j&(1<<x)) tmp+=s[x];
            }
 
            ++mp[j][tmp];
        }
    }
 
    for (int m=0; m<(1<<K); ++m) {
        ll tmp=0;
        for (auto u : mp[m]) tmp+=u.second*(u.second-1)/2;
        ans[4-__builtin_popcount(m)]+=tmp;
    }
 
    ll k;
    if (d == 1) k=ans[1]-ans[0];
    else if (d == 2) k=ans[2]-3*(ans[1]-ans[0]);
    else if (d == 3) k=ans[3]-2*ans[2]+3*(ans[1]-ans[0]);
    else k=ans[4]-ans[3]+ans[2]-ans[1]+ans[0];
    k=max(0ll, k);
    cout<<k<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 5 ms 980 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 51 ms 3308 KB Output is correct
5 Correct 67 ms 3700 KB Output is correct
6 Correct 65 ms 3740 KB Output is correct
7 Correct 56 ms 3260 KB Output is correct
8 Correct 79 ms 3928 KB Output is correct
9 Correct 144 ms 5452 KB Output is correct
10 Correct 147 ms 5720 KB Output is correct
11 Correct 68 ms 3948 KB Output is correct
12 Correct 125 ms 5548 KB Output is correct
13 Correct 73 ms 4060 KB Output is correct
14 Correct 67 ms 3916 KB Output is correct
15 Correct 143 ms 5560 KB Output is correct
16 Correct 164 ms 11244 KB Output is correct
17 Correct 296 ms 14812 KB Output is correct
18 Correct 182 ms 12256 KB Output is correct
19 Correct 218 ms 13624 KB Output is correct
20 Correct 238 ms 14764 KB Output is correct