답안 #496385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496385 2021-12-21T06:43:34 Z XBoRickie PIN (CEOI10_pin) C++14
100 / 100
140 ms 18560 KB
#include <bits/stdc++.h>
using namespace std;
// Typedef
typedef long double                ld;
typedef long long int              int64;
typedef unsigned long long int     uint64;
typedef std::pair<int, int>        PII;
typedef std::pair<int64, int64>    PLL;
typedef std::vector<int>           VI;
typedef std::vector<long long>     VLL;
// Define For-loop
#define FOR(i, j, k, in)           for (int i = (j); i < (k) ; i += (in))
#define FORW(i, j, k, in)          for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in)          for (int i = (j); i >= (k); i -= (in))
// Define Data structure func
#define all(cont)                  cont.begin(), cont.end()
#define rall(cont)                 cont.rbegin(), cont.rend()
#define sz(cont)                   int((cont).size())
#define pb                         push_back
#define mp                         make_pair
#define fi                         first
#define se                         second
// Define number
#define IINF                       0x3f3f3f3f
#define LLINF                      1000111000111000111LL
#define PI                         3.1415926535897932384626433832795
// Other
#define lend                       '\n'
#define hardio(name)               freopen(name".inp","r",stdin), freopen(name".out","w",stdout);
void FastIO() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin.exceptions(cin.failbit); srand(time(NULL)); }

const int N = 5e5 + 6, base = 331, LG = (1 << 4) - 1;
const int MOD = 1e9 + 7, MOD2 = 1e9 + 9;
// ======================================================================

int n, d;

map<int, int> hsh;
int cnt[56] = {};
int64 val[6] = {};
string s[N] = {};

/*
    abcd
    => 4: abcd = 1
    => 3: abc abd acd bcd = 4
    => 2: ab ac ad bc bd cb = 6
    => 1: a b c d = 4
    ======================
    We can see the answer will be overlapping:
        + With 3 characters, there'll be 4C3 way to abstract [choose 4]
        + With 2 characters, there'll be 4C2 way to abstract [choose 4], 3C2 way to abstract [choose 3]
        + With 1 characters, there'll be 4C1 way to abstract [choose 4], 3C1 way to abstract [choose 3], 2C1 way to abstract [choose 2]
        + With 0 characters, 4C0 + 3C0 + 2C0 + 1C0
*/

int main(int argc, char* argv[]) { FastIO();

    cin >> n >> d;
    FORW(i, 1, n, 1) { cin >> s[i]; s[i] = '$' + s[i]; }
    FORW(i, 1, LG, 1) cnt[i] = cnt[i >> 1] + (i & 1);

    FORW(mask, 0, LG, 1) {
        hsh.clear();
        FORW(i, 1, n, 1) {
            int sum = 0;
            FORW(k, 1, 4, 1) sum = sum * base + ((mask >> (k - 1)) & 1 ? s[i][k] : 1);
            val[cnt[mask]] += hsh[sum];
            hsh[sum]++;
        }
    }

    val[3] -= 4 * val[4];
    val[2] -= 6 * val[4] + 3 * val[3];
    val[1] -= 4 * val[4] + 3 * val[3] + 2 * val[2];
    val[0] -= val[1] + val[2] + val[3] + val[4];

    cout << val[4 - d] << '\n';

    return 0; }
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15952 KB Output is correct
2 Correct 13 ms 15952 KB Output is correct
3 Correct 10 ms 15952 KB Output is correct
4 Correct 46 ms 16880 KB Output is correct
5 Correct 50 ms 17168 KB Output is correct
6 Correct 52 ms 17164 KB Output is correct
7 Correct 42 ms 16888 KB Output is correct
8 Correct 55 ms 17308 KB Output is correct
9 Correct 85 ms 18280 KB Output is correct
10 Correct 93 ms 18440 KB Output is correct
11 Correct 54 ms 17244 KB Output is correct
12 Correct 88 ms 18324 KB Output is correct
13 Correct 60 ms 17408 KB Output is correct
14 Correct 54 ms 17236 KB Output is correct
15 Correct 92 ms 18380 KB Output is correct
16 Correct 97 ms 17716 KB Output is correct
17 Correct 136 ms 18504 KB Output is correct
18 Correct 104 ms 17896 KB Output is correct
19 Correct 123 ms 18172 KB Output is correct
20 Correct 140 ms 18560 KB Output is correct