Submission #135426

# Submission time Handle Problem Language Result Execution time Memory
135426 2019-07-24T05:25:39 Z 임유진(#3251) PIN (CEOI10_pin) C++14
75 / 100
1000 ms 7228 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];
const int pw[4] = {36 * 36 * 36, 36 * 36, 36, 1};

int main() {
	ios_base::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);

	lint zero = 0, one = 0, two = 0, thr = 0, fou = 0;
	for(int i = 0; i < N; i++) {
		//printf("two = %lld\n", two);
		char tmp[4];
		int x = 0;
		for(int j = 0; j < 4; j++) {
			tmp[j] = p[i][j];
			x += p[i][j] * pw[j];
		}
		two += cnt[x];
		for(int j = 0; j < 4; j++) {
			for(tmp[j] = 0, x -= p[i][j] * pw[j]; tmp[j] < 36; tmp[j]++, x += pw[j]) if(tmp[j] != p[i][j]) {
				for(int k = j + 1; k < 4; k++) {
					for(tmp[k] = 0, x -= p[i][k] * pw[k]; tmp[k] < 36; tmp[k]++, x += pw[k]) if(tmp[k] != p[i][k]) 
						fou += cnt[x]++;
					tmp[k] = p[i][k];
					x += (p[i][k] - 36) * pw[k];
				}
				thr += cnt[x];
			}
			tmp[j] = p[i][j];
			x += (p[i][j] - 36) * pw[j];
		}
	}
	for(int i = 0; i < TOTAL; i++) cnt[i] = 0;
	for(int i = 0; i < N; i++) {
		char tmp[4];
		int x = 0;
		for(int j = 0; j < 4; j++) {
			tmp[j] = p[i][j];
			x += p[i][j] * pw[j];
		}
		zero += cnt[x]++;
		for(int j = 0; j < 4; j++) {
			for(tmp[j] = 0, x -= p[i][j] * pw[j]; tmp[j] < 36; tmp[j]++, x += pw[j]) if(tmp[j] != p[i][j]) 
				one += cnt[x];
			tmp[j] = p[i][j];
			x += (p[i][j] - 36) * pw[j];
		}
	}

	thr = (thr - 105 * one - 68 * two) / 3;
	fou = (fou - 3570 * one - 1296 * two - 204 * thr) / 6;
	//printf("zero = %lld, one = %lld, two = %lld, thr = %lld, fou = %lld\n", zero, one, two, thr, fou);

	if(D == 1) ans = one;
	else if(D == 2) ans = two;
	else if(D == 3) ans = thr;
	else ans = fou;

	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 6904 KB Output is correct
2 Correct 44 ms 6904 KB Output is correct
3 Correct 40 ms 7032 KB Output is correct
4 Correct 435 ms 7032 KB Output is correct
5 Correct 548 ms 7032 KB Output is correct
6 Correct 580 ms 7084 KB Output is correct
7 Correct 451 ms 7060 KB Output is correct
8 Correct 600 ms 7032 KB Output is correct
9 Correct 972 ms 7180 KB Output is correct
10 Execution timed out 1066 ms 7200 KB Time limit exceeded
11 Correct 575 ms 7160 KB Output is correct
12 Execution timed out 1020 ms 7228 KB Time limit exceeded
13 Correct 651 ms 7108 KB Output is correct
14 Correct 589 ms 7100 KB Output is correct
15 Execution timed out 1022 ms 7188 KB Time limit exceeded
16 Correct 730 ms 7120 KB Output is correct
17 Execution timed out 1060 ms 7132 KB Time limit exceeded
18 Correct 865 ms 7148 KB Output is correct
19 Correct 956 ms 7176 KB Output is correct
20 Execution timed out 1073 ms 7160 KB Time limit exceeded