Submission #1323180

#TimeUsernameProblemLanguageResultExecution timeMemory
1323180bahaktlPIN (CEOI10_pin)C++20
65 / 100
14 ms18392 KiB
#include <bits/stdc++.h>

#define int long long 
#define pb push_back
using namespace std;

const int N=2e5+10;
const int inf=1e18;
const int mod=1e9+7;

pair<int,int> r[N],c[N];

int cnt[39][39][39][39];

signed main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    while(T--) {
        int n,k;
        cin>>n>>k;
        string s[n+1];
        int ans=0,ans1=0,ans2=0,ans3=0;
        for(int i=1;i<=n;i++) {
            cin>>s[i];
            int ch1=0,ch2,ch3,ch4;
            if(s[i][0]>='a') ch1=s[i][0]-'a'+10;
            else ch1=s[i][0]-'0';
            if(s[i][1]>='a') ch2=s[i][1]-'a'+10;
            else ch2=s[i][1]-'0';
            if(s[i][2]>='a') ch3=s[i][2]-'a'+10;
            else ch3=s[i][2]-'0';
            if(s[i][3]>='a') ch4=s[i][3]-'a'+10;
            else ch4=s[i][3]-'0';
            ans+=cnt[ch1][ch2][ch3][38]+
            cnt[ch1][ch2][38][ch4]+
            cnt[ch1][38][ch3][ch4]+
            cnt[38][ch2][ch3][ch4];
            ans1+=cnt[ch1][ch2][38][38]+
            cnt[ch1][38][ch3][38]+
            cnt[38][ch2][ch3][38]+
            cnt[ch1][38][38][ch4]+
            cnt[38][ch2][38][ch4]+
            cnt[38][38][ch3][ch4];
            ans1-=cnt[38][ch2][ch3][ch4]*3+cnt[ch1][38][ch3][ch4]*3+cnt[ch1][ch2][38][ch4]*3+cnt[ch1][ch2][ch3][38]*3;
            ans2+=cnt[38][38][38][ch4]+
            cnt[38][38][ch3][38]+
            cnt[38][ch2][38][38]+
            cnt[ch1][38][38][38];
            ans2-=cnt[38][ch2][ch3][ch4]*3+cnt[ch1][38][ch3][ch4]*3+cnt[ch1][ch2][38][ch4]*3+cnt[ch1][ch2][ch3][38]*3;
            ans2-=cnt[ch1][ch2][38][38]*2+cnt[ch1][38][ch3][38]*2+cnt[38][ch2][ch3][38]*2+cnt[ch1][38][38][ch4]*2+cnt[38][ch2][38][ch4]*2+cnt[38][38][ch3][ch4]*2;
            ans3+=cnt[38][38][38][38];
            ans3-=cnt[38][ch2][ch3][ch4]+cnt[ch1][38][ch3][ch4]+cnt[ch1][ch2][38][ch4]+cnt[ch1][ch2][ch3][38];
            ans3-=cnt[ch1][ch2][38][38]+cnt[ch1][38][ch3][38]+cnt[38][ch2][ch3][38]+cnt[ch1][38][38][ch4]+cnt[38][ch2][38][ch4]+cnt[38][38][ch3][ch4];
            ans3-=cnt[38][38][38][ch4]+cnt[38][38][ch3][38]+cnt[38][ch2][38][38]+cnt[ch1][38][38][38];
            cnt[ch1][ch2][ch3][38]++;
            cnt[ch1][ch2][38][ch4]++;
            cnt[ch1][38][ch3][ch4]++;
            cnt[38][ch2][ch3][ch4]++;
            cnt[ch1][ch2][38][38]++;
            cnt[ch1][38][ch3][38]++;
            cnt[38][ch2][ch3][38]++;
            cnt[ch1][38][38][ch4]++;
            cnt[38][ch2][38][ch4]++;
            cnt[38][38][ch3][ch4]++;
            cnt[38][38][38][ch4]++;
            cnt[38][38][ch3][38]++;
            cnt[38][ch2][38][38]++;
            cnt[ch1][38][38][38];
            cnt[38][38][38][38]++;

            // cout<<ch1<<' '<<ch2<<' '<<ch3<<' '<<ch4<<endl;
        }
        if(n<=2000) {
            int ans=0;
            for(int i=1;i<=n;i++) {
                for(int j=i+1;j<=n;j++) {
                    if(i==j) continue;
                    int cnt=0;
                    for(int l=0;l<4;l++) {
                        if(s[i][l]!=s[j][l]) cnt++;
                    }
                    if(cnt==k) ans++;
                }
            }
            cout<<ans<<"\n";
            continue;
        }
        // if(k==1) {
        //     int ans=0;
        //     for(int i=1;i<=n;i++) {
        //         int ch1=0,ch2,ch3,ch4;
        //         if(s[i][0]>='a') ch1=s[i][0]-'a'+10;
        //         else ch1=s[i][0]-'0';
        //         if(s[i][1]>='a') ch2=s[i][1]-'a'+10;
        //         else ch2=s[i][1]-'0';
        //         if(s[i][2]>='a') ch3=s[i][2]-'a'+10;
        //         else ch3=s[i][2]-'0';
        //         if(s[i][3]>='a') ch4=s[i][3]-'a'+10;
        //         else ch4=s[i][3]-'0';
        //         ans+=cnt[ch1][ch2][ch3][38]+
        //         cnt[ch1][ch2][38][ch4]+
        //         cnt[ch1][38][ch3][ch4]+
        //         cnt[38][ch2][ch3][ch4]-4;
        //     }
        if(k==4) cout<<ans3<<"\n";
        if(k==3) cout<<ans2<<"\n";
        if(k==2) cout<<ans1<<'\n';
        if(k==1) cout<<ans<<"\n";
    }
}
// 1 2 3 4 5 6 7
#Verdict Execution timeMemoryGrader output
Fetching results...