Submission #135377

# Submission time Handle Problem Language Result Execution time Memory
135377 2019-07-24T04:29:44 Z 임유진(#3251) PIN (CEOI10_pin) C++14
30 / 100
72 ms 7288 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;

const int MAXN = 50005;
const int TOTAL = 36 * 36 * 36 * 36;

char p[MAXN][5];
int cnt[TOTAL];

int tonum(char s[]) { return 36 * 36 * 36 * int(s[0]) + 36 * 36 * int(s[1]) + 36 * int(s[2]) + int(s[3]); }

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, D;
	lint ans = 0ll;

	cin >> N >> D;
	for(int i = 0; i < N; i++) cin >> p[i];

	for(int i = 0; i < N; i++) for(int j = 0; j < 4; j++)
		p[i][j] = '0' <= p[i][j] && p[i][j] <= '9' ? (p[i][j] - '0') : (p[i][j] - 'a' + 10);

	if(D == 1) {
		for(int i = 0; i < N; i++) {
			char tmp[4];
			for(int j = 0; j < 4; j++) tmp[j] = p[i][j];
			for(int j = 0; j < 4; j++) {
				for(int k = 0; k < 36; k++) if(k != p[i][j]) {
					tmp[j] = k;
					ans += cnt[tonum(tmp)];
					//if(cnt[tonum(tmp)] != 0) printf("j = %d, tonum(%d %d %d %d) = %d\n", j, tmp[0], tmp[1], tmp[2], tmp[3], tonum(tmp));
				}
				tmp[j] = p[i][j];
			}
			cnt[tonum(p[i])]++;
			//printf("tonum(p[i]) = %d\n", tonum(p[i]));
			//printf("ans = %lld\n", ans);
		}
	}
	else if(D == 2) {
		for(int i = 0; i < N; i++) {
			//printf("i = %d\n", i);
			char tmp[4];
			for(int j = 0; j < 4; j++) tmp[j] = p[i][j];
			for(int j = 0; j < 4; j++) {
				for(int k = 0; k < 36; k++) if(k != p[i][j]) {
					tmp[j] = k;
					ans += cnt[tonum(tmp)];
					//if(cnt[tonum(tmp)] != 0) printf("j = %d, tonum(%d %d %d %d) = %d\n", j, tmp[0], tmp[1], tmp[2], tmp[3], tonum(tmp));
					cnt[tonum(tmp)]++;
				}
				tmp[j] = p[i][j];
			}
		}
		ans /= 2;
		for(int i = 0; i < TOTAL; i++) cnt[i] = 0;
		for(int i = 0; i < N; i++) {
			ans -= cnt[tonum(p[i])];
			cnt[tonum(p[i])]++;
		}
	}

	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1656 KB Output is correct
2 Incorrect 12 ms 6904 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Correct 18 ms 1784 KB Output is correct
5 Correct 20 ms 1784 KB Output is correct
6 Incorrect 37 ms 7032 KB Output isn't correct
7 Incorrect 32 ms 7032 KB Output isn't correct
8 Correct 23 ms 1784 KB Output is correct
9 Correct 33 ms 1916 KB Output is correct
10 Incorrect 64 ms 7120 KB Output isn't correct
11 Incorrect 40 ms 7036 KB Output isn't correct
12 Incorrect 6 ms 504 KB Output isn't correct
13 Incorrect 4 ms 504 KB Output isn't correct
14 Incorrect 4 ms 504 KB Output isn't correct
15 Incorrect 6 ms 632 KB Output isn't correct
16 Correct 39 ms 7032 KB Output is correct
17 Incorrect 72 ms 7288 KB Output isn't correct
18 Incorrect 5 ms 504 KB Output isn't correct
19 Incorrect 5 ms 504 KB Output isn't correct
20 Incorrect 6 ms 632 KB Output isn't correct