Submission #135404

# Submission time Handle Problem Language Result Execution time Memory
135404 2019-07-24T04:56:28 Z 임유진(#3251) PIN (CEOI10_pin) C++14
10 / 100
1000 ms 7160 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);

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

	//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 99 ms 7032 KB Output is correct
2 Correct 93 ms 6904 KB Output is correct
3 Incorrect 75 ms 6904 KB Output isn't correct
4 Execution timed out 1065 ms 7032 KB Time limit exceeded
5 Execution timed out 1085 ms 7032 KB Time limit exceeded
6 Execution timed out 1072 ms 7032 KB Time limit exceeded
7 Execution timed out 1075 ms 7032 KB Time limit exceeded
8 Execution timed out 1074 ms 7032 KB Time limit exceeded
9 Execution timed out 1058 ms 7160 KB Time limit exceeded
10 Execution timed out 1063 ms 7160 KB Time limit exceeded
11 Execution timed out 1077 ms 7032 KB Time limit exceeded
12 Execution timed out 1073 ms 7160 KB Time limit exceeded
13 Execution timed out 1080 ms 7032 KB Time limit exceeded
14 Execution timed out 1084 ms 7036 KB Time limit exceeded
15 Execution timed out 1070 ms 7160 KB Time limit exceeded
16 Execution timed out 1071 ms 7036 KB Time limit exceeded
17 Execution timed out 1037 ms 7160 KB Time limit exceeded
18 Execution timed out 1064 ms 7032 KB Time limit exceeded
19 Execution timed out 1064 ms 7160 KB Time limit exceeded
20 Execution timed out 1054 ms 7132 KB Time limit exceeded