답안 #357560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
357560 2021-01-24T06:15:43 Z blue PIN (CEOI10_pin) C++17
60 / 100
36 ms 10476 KB
#include <iostream>
#include <vector>
using namespace std;

/*
There are 36^4 = 1679616 possibilities for the PIN.

Let them be numbered from 0 to 1679615.
Two PINS have one difference if their
*/

int adj(char c)
{
    if(c == '0') return 1;
    else if('1' <= c && c <= '9') return (c - '1') + 2;
    else return (c - 'a') + 11;
}

int ct[37][37][37][37];

int main()
{
    int N, D;
    cin >> N >> D;

    string S;
    vector< vector<int> > T(N, vector<int>(4));
    for(int i = 0; i < N; i++)
    {
        cin >> S;
        for(int j = 0; j < 4; j++) T[i][j] = adj(S[j]);
        for(int mask = 0; mask < (1 << 4); mask++)
        {
            ct[(mask & (1 << 0)) ? T[i][0] : 0]
              [(mask & (1 << 1)) ? T[i][1] : 0]
              [(mask & (1 << 2)) ? T[i][2] : 0]
              [(mask & (1 << 3)) ? T[i][3] : 0]++;
        }
    }

    long long res = 0;

    vector<int> X;

    if(D == 1)
    {
        for(int i = 0; i < N; i++)
        {
            X = T[i];
            res += ct[0][X[1]][X[2]][X[3]];
            res += ct[X[0]][0][X[2]][X[3]];
            res += ct[X[0]][X[1]][0][X[3]];
            res += ct[X[0]][X[1]][X[2]][0];
            res -= 4 * ct[X[0]][X[1]][X[2]][X[3]];
        }
    }
    else if(D == 2)
    {
        for(int i = 0; i < N; i++)
        {
            X = T[i];
            res += ct[0][0][X[2]][X[3]];
            res += ct[0][X[1]][0][X[3]];
            res += ct[0][X[1]][X[2]][0];
            res += ct[X[0]][0][0][X[3]];
            res += ct[X[0]][0][X[2]][0];
            res += ct[X[0]][X[1]][0][0];

            res -= 3 * ct[0][X[1]][X[2]][X[3]];
            res -= 3 * ct[X[0]][0][X[2]][X[3]];
            res -= 3 * ct[X[0]][X[1]][0][X[3]];
            res -= 3 * ct[X[0]][X[1]][X[2]][0];

            res += 6 * ct[X[0]][X[1]][X[2]][X[3]];
        }


    }

    res /= 2;
    cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2028 KB Output is correct
2 Correct 2 ms 2028 KB Output is correct
3 Incorrect 2 ms 1900 KB Output isn't correct
4 Correct 10 ms 2924 KB Output is correct
5 Correct 14 ms 3180 KB Output is correct
6 Correct 12 ms 3180 KB Output is correct
7 Correct 10 ms 2924 KB Output is correct
8 Correct 14 ms 3436 KB Output is correct
9 Correct 20 ms 4332 KB Output is correct
10 Correct 23 ms 4588 KB Output is correct
11 Correct 20 ms 3336 KB Output is correct
12 Incorrect 20 ms 4460 KB Output isn't correct
13 Incorrect 20 ms 3564 KB Output isn't correct
14 Incorrect 13 ms 3308 KB Output isn't correct
15 Incorrect 21 ms 4460 KB Output isn't correct
16 Correct 23 ms 9452 KB Output is correct
17 Correct 36 ms 10476 KB Output is correct
18 Incorrect 25 ms 9708 KB Output isn't correct
19 Incorrect 28 ms 10092 KB Output isn't correct
20 Incorrect 32 ms 10348 KB Output isn't correct