# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
287526 | 2020-08-31T18:58:04 Z | PeppaPig | PIN (CEOI10_pin) | C++14 | 783 ms | 12268 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 5e4 + 5; const int B = 98765431; int n, d; map<long, int> mp[1 << 4]; vector<int> bit[5]; char S[N][4]; long get_hash(char *s, int b) { long ret = 0; for(int i = 0; i < 4; i++) if(b >> i & 1) ret = ret * B + s[i]; return ret; } int main() { scanf("%d %d", &n, &d); for(int i = 0; i < (1 << 4); i++) bit[__builtin_popcount(i)].emplace_back(i); for(int i = 1; i <= n; i++) { scanf(" %s", S[i]); for(int j = 0; j < (1 << 4); j++) ++mp[j][get_hash(S[i], j)]; } long ans = 0; for(int i = 1; i <= n; i++) { vector<long> sum(6); sum[0] = n - 1; for(int z = max(4 - d, 1); z <= min(4 - d + 1, 4); z++) { for(int st = 1; st < (1 << (int)bit[z].size()); st++) { int all = 0; for(int j = 0; j < (int)bit[z].size(); j++) if(st >> j & 1) all |= bit[z][j]; int cnt = mp[all][get_hash(S[i], all)]; if(__builtin_popcount(st) & 1) sum[z] += cnt; else sum[z] -= cnt; } --sum[z]; } ans += sum[4 - d] - sum[4 - d + 1]; } printf("%lld\n", ans / 2); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 896 KB | Output is correct |
2 | Correct | 14 ms | 896 KB | Output is correct |
3 | Correct | 5 ms | 768 KB | Output is correct |
4 | Correct | 90 ms | 2808 KB | Output is correct |
5 | Correct | 107 ms | 3192 KB | Output is correct |
6 | Correct | 247 ms | 3192 KB | Output is correct |
7 | Correct | 195 ms | 2936 KB | Output is correct |
8 | Correct | 118 ms | 3448 KB | Output is correct |
9 | Correct | 196 ms | 4728 KB | Output is correct |
10 | Correct | 506 ms | 4984 KB | Output is correct |
11 | Correct | 263 ms | 3448 KB | Output is correct |
12 | Correct | 502 ms | 4872 KB | Output is correct |
13 | Correct | 304 ms | 3576 KB | Output is correct |
14 | Correct | 119 ms | 3320 KB | Output is correct |
15 | Correct | 235 ms | 4984 KB | Output is correct |
16 | Correct | 278 ms | 9340 KB | Output is correct |
17 | Correct | 783 ms | 12220 KB | Output is correct |
18 | Correct | 360 ms | 10104 KB | Output is correct |
19 | Correct | 389 ms | 11256 KB | Output is correct |
20 | Correct | 499 ms | 12268 KB | Output is correct |