Submission #486401

# Submission time Handle Problem Language Result Execution time Memory
486401 2021-11-11T15:00:06 Z Rainbowbunny PIN (CEOI10_pin) C++17
100 / 100
221 ms 24708 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 5;

int pw[10];

int n, d;
int cnt[10], tt[10];
string s[MAXN];
map <int, int> M[30];

int Get(char c)
{
    if(c >= '0' and c <= '9')
    {
        return c - '0';
    }
    else
    {
        return c - 'a' + 10;
    }
}

int main()
{
    // freopen("Input.txt", "r", stdin);
    // freopen("Output2.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    pw[0] = 1;
    for(int i = 1; i <= 3; i++)
    {
        pw[i] = pw[i - 1] * 36;
    }
    cin >> n >> d;
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i];
        for(int j = 0; j <= 4; j++)
        {
            tt[j] = 0;
        }
        for(int j = 0; j < 1 << 4; j++)
        {
            int cur = 0;
            for(int k = 0; k < 4; k++)
            {
                if(!(j & (1 << k)))
                {
                    cur += pw[k] * Get(s[i][k]);
                }
            }
            tt[__builtin_popcount(j)] += M[j][cur]; 
            M[j][cur]++;
        }
        for(int j = 1; j <= 4; j++)
        {
            // cout << tt[j] << ' ';
        }
        tt[1] -= 4 * tt[0];
        tt[2] -= 3 * tt[1];
        tt[2] -= 6 * tt[0];
        tt[3] -= 4 * tt[0];
        tt[3] -= 3 * tt[1];
        tt[3] -= 2 * tt[2];
        tt[4] = (i - 1) - tt[0] - tt[1] - tt[2] - tt[3];
        for(int j = 0; j <= 4; j++)
        {
            cnt[j] += tt[j];
        }
        // cout << '\n';
        for(int j = 0; j <= 4; j++)
        {
            // cout << tt[j] << ' ';
        }
        // cout << '\n';
    }
    cout << cnt[d] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16360 KB Output is correct
2 Correct 12 ms 16332 KB Output is correct
3 Correct 10 ms 16204 KB Output is correct
4 Correct 54 ms 17836 KB Output is correct
5 Correct 65 ms 17960 KB Output is correct
6 Correct 76 ms 17992 KB Output is correct
7 Correct 66 ms 17732 KB Output is correct
8 Correct 83 ms 18200 KB Output is correct
9 Correct 115 ms 19012 KB Output is correct
10 Correct 159 ms 19348 KB Output is correct
11 Correct 75 ms 18108 KB Output is correct
12 Correct 141 ms 19232 KB Output is correct
13 Correct 98 ms 18408 KB Output is correct
14 Correct 84 ms 18172 KB Output is correct
15 Correct 121 ms 19172 KB Output is correct
16 Correct 190 ms 22548 KB Output is correct
17 Correct 210 ms 24708 KB Output is correct
18 Correct 167 ms 23140 KB Output is correct
19 Correct 210 ms 24044 KB Output is correct
20 Correct 221 ms 24644 KB Output is correct