# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
287526 | PeppaPig | PIN (CEOI10_pin) | C++14 | 783 ms | 12268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |