Submission #1323189

#TimeUsernameProblemLanguageResultExecution timeMemory
1323189kkkkkPIN (CEOI10_pin)C++20
30 / 100
13 ms16656 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 37;
const int M = 5e4 + 11;
int f[N][N][N][N];
int to[256];
string s[M];

int f1(int a, int b, int c, int d){
    return f[a][b][c][0] + f[a][b][0][d] + f[a][0][c][d] + f[0][b][c][d] - f[a][b][c][d] * 4;
}

int f4(int a, int b, int c, int d){
    return f[0][0][0][0] - f[a][b][c][d];
}

int f2(int a, int b, int c, int d){
    return
    f[a][b][0][0] + f[a][0][c][0] + f[a][0][0][d] +
    f[0][b][c][0] + f[0][b][0][d] +
    f[0][0][c][d];
    - 
    (f[a][b][c][0] + f[a][b][0][d] + f[0][b][c][d] + f[a][0][c][d]) * 3;
    +
    f[a][b][c][d] * 6;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int toto = 0;
    for(char c = '0'; c <= '9'; c++) to[c] = ++toto;
    for(char c = 'a'; c <= 'z'; c++) to[c] = ++toto;

    int n, D, ans = 0;
    cin >> n >> D;

    for(int i = 1; i <= n; i++){
        cin >> s[i];
        int a = to[s[i][0]];
        int b = to[s[i][1]];
        int c = to[s[i][2]];
        int d = to[s[i][3]];
        
        if(D == 1){
            ans += f1(a, b, c, d);
        }
        if(D == 2){
            ans += f2(a, b, c, d);
        }
        if(D == 3){

        }
        if(D == 4){
            ans += f4(a, b, c, d);
        }

        f[a][b][c][d]++;
        //
        f[a][b][c][0]++;
        f[a][b][0][d]++;
        f[a][0][c][d]++;
        f[0][b][c][d]++;
        // 
        f[a][b][0][0]++;
        f[a][0][c][0]++;
        f[a][0][0][d]++;
        f[0][b][c][0]++;
        f[0][b][0][d]++;
        f[0][0][c][d]++;
        //
        f[a][0][0][0]++;
        f[0][b][0][0]++;
        f[0][0][c][0]++;
        f[0][0][0][d]++;
        //
        f[0][0][0][0]++;
        // 
        // cout << ans << '\n';
    }

    cout << ans;
}
// subete no mono no owari wa sugu ni yattekuru
#Verdict Execution timeMemoryGrader output
Fetching results...