제출 #357568

#제출 시각아이디문제언어결과실행 시간메모리
357568bluePIN (CEOI10_pin)C++17
100 / 100
46 ms10348 KiB
#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]++; } } vector<long long> res(5, 0); vector<int> X; for(int i = 0; i < N; i++) { X = T[i]; res[1] += ct[0][X[1]][X[2]][X[3]]; res[1] += ct[X[0]][0][X[2]][X[3]]; res[1] += ct[X[0]][X[1]][0][X[3]]; res[1] += ct[X[0]][X[1]][X[2]][0]; res[1] -= 4 * ct[X[0]][X[1]][X[2]][X[3]]; } for(int i = 0; i < N; i++) { X = T[i]; res[2] += ct[0][0][X[2]][X[3]]; res[2] += ct[0][X[1]][0][X[3]]; res[2] += ct[0][X[1]][X[2]][0]; res[2] += ct[X[0]][0][0][X[3]]; res[2] += ct[X[0]][0][X[2]][0]; res[2] += ct[X[0]][X[1]][0][0]; res[2] -= 6 * ct[X[0]][X[1]][X[2]][X[3]]; } res[2] -= 3 * res[1]; for(int i = 0; i < N; i++) { X = T[i]; res[3] += ct[0][0][0][X[3]]; res[3] += ct[0][0][X[2]][0]; res[3] += ct[0][X[1]][0][0]; res[3] += ct[X[0]][0][0][0]; res[3] -= 4 * ct[X[0]][X[1]][X[2]][X[3]]; } res[3] -= 3 * res[1]; res[3] -= 2 * res[2]; for(int i = 0; i < N; i++) { X = T[i]; res[4] += ct[0][0][0][0]; res[4] -= ct[X[0]][X[1]][X[2]][X[3]]; } res[4] -= res[1]; res[4] -= res[2]; res[4] -= res[3]; res[D] /= 2; cout << res[D] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...