Submission #135418

# Submission time Handle Problem Language Result Execution time Memory
135418 2019-07-24T05:09:27 Z 임유진(#3251) PIN (CEOI10_pin) C++14
50 / 100
1000 ms 7260 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 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);

	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];
		}
	}

	//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;

	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 6904 KB Output is correct
2 Correct 39 ms 6904 KB Output is correct
3 Incorrect 32 ms 6904 KB Output isn't correct
4 Correct 429 ms 7160 KB Output is correct
5 Correct 510 ms 7204 KB Output is correct
6 Correct 503 ms 7084 KB Output is correct
7 Correct 412 ms 7056 KB Output is correct
8 Correct 572 ms 7160 KB Output is correct
9 Correct 926 ms 7172 KB Output is correct
10 Execution timed out 1008 ms 7208 KB Time limit exceeded
11 Correct 552 ms 7092 KB Output is correct
12 Incorrect 981 ms 7188 KB Output isn't correct
13 Incorrect 601 ms 7104 KB Output isn't correct
14 Incorrect 566 ms 7088 KB Output isn't correct
15 Incorrect 968 ms 7188 KB Output isn't correct
16 Correct 713 ms 7132 KB Output is correct
17 Execution timed out 1045 ms 7196 KB Time limit exceeded
18 Incorrect 821 ms 7144 KB Output isn't correct
19 Incorrect 952 ms 7176 KB Output isn't correct
20 Execution timed out 1048 ms 7260 KB Time limit exceeded