답안 #320204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320204 2020-11-07T23:27:08 Z Karen124 PIN (CEOI10_pin) C++14
100 / 100
143 ms 51428 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e5 + 5;
const ll M = 36 + 5;
const ll K = 16 + 5; 
const ll O = 10;
ll n, d, z[O];
ll ans[O], ansp[O], res[O];
ll cn[K][M][M][M][M];
unordered_map <char, ll> f;
string a[N];
int main (){
    f['0'] = 1; f['1'] = 2; f['2'] = 3; f['3'] = 4; f['4'] = 5; f['5'] = 6; f['6'] = 7; f['7'] = 8;
    f['8'] = 9; f['9'] = 10; f['a'] = 11; f['b'] = 12; f['c'] = 13; f['d'] = 14; f['e'] = 15; f['f'] = 16;
    f['g'] = 17; f['h'] = 18; f['i'] = 19; f['j'] = 20; f['k'] = 21; f['l'] = 22; f['m'] = 23; f['n'] = 24;
    f['o'] = 25; f['p'] = 26; f['q'] = 27; f['r'] = 28; f['s'] = 29; f['t'] = 30; f['u'] = 31; f['v'] = 32;
    f['w'] = 33; f['x'] = 34; f['y'] = 35; f['z'] = 36; 
    cin >> n >> d;
    for (ll i = 0; i < n; i++){
        cin >> a[i];
        fill(ansp, ansp + O, 0);
        for (ll msk = 0; msk < 16; msk++){
            fill(z, z + O, 0);
            for (int j = 0; j < 4; j++){
                if ((msk >> j) & 1){
                    z[j] = f[a[i][j]];
                }
            }
            ansp[__builtin_popcount(msk)] += cn[msk][z[0]][z[1]][z[2]][z[3]]; 
        }
        ansp[3] += -4ll * ansp[4];
        ansp[2] += -3ll * ansp[3] -6ll * ansp[4];
        ansp[1] += -2ll * ansp[2] -3ll * ansp[3] -4ll * ansp[4];
        ansp[0] += -1ll * ansp[1] -1ll * ansp[2] -1ll * ansp[3] -1ll * ansp[4];
        for (int j = 0; j < 4; j++) ans[j] += ansp[j];
        for (ll msk = 0; msk < 16; msk++){
            fill(z, z + O, 0);
            for (int j = 0; j < 4; j++){
                if ((msk >> j) & 1){
                    z[j] = f[a[i][j]];
                }
            }
            cn[msk][z[0]][z[1]][z[2]][z[3]] ++;
        }
    }    
    cout << ans[4 - d] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10476 KB Output is correct
2 Correct 11 ms 10368 KB Output is correct
3 Correct 10 ms 10092 KB Output is correct
4 Correct 43 ms 11244 KB Output is correct
5 Correct 55 ms 11236 KB Output is correct
6 Correct 51 ms 11116 KB Output is correct
7 Correct 42 ms 11116 KB Output is correct
8 Correct 58 ms 11116 KB Output is correct
9 Correct 86 ms 11244 KB Output is correct
10 Correct 95 ms 11236 KB Output is correct
11 Correct 53 ms 11116 KB Output is correct
12 Correct 87 ms 11108 KB Output is correct
13 Correct 59 ms 11116 KB Output is correct
14 Correct 55 ms 11244 KB Output is correct
15 Correct 90 ms 11116 KB Output is correct
16 Correct 113 ms 51300 KB Output is correct
17 Correct 143 ms 51300 KB Output is correct
18 Correct 115 ms 51300 KB Output is correct
19 Correct 131 ms 51300 KB Output is correct
20 Correct 141 ms 51428 KB Output is correct