Submission #135384

# Submission time Handle Problem Language Result Execution time Memory
135384 2019-07-24T04:33:33 Z 이온조(#3249) PIN (CEOI10_pin) C++14
100 / 100
662 ms 11972 KB
#include <bits/stdc++.h>
using namespace std;

int N, D;
unordered_map<string, int> mp;
string S[50009];

string make(string S, int msk) {
	for(int i=0; i<4; i++) if((msk >> i) & 1) S[i] = '_';
	return S;
}

long long solve1() {
	long long ans = 0;
	for(int i=1; i<=N; i++) {
		ans += mp[make(S[i], 1)];
		ans += mp[make(S[i], 2)];
		ans += mp[make(S[i], 4)];
		ans += mp[make(S[i], 8)];
	}
	return ans;
}

long long solve2() {
	long long ans = 0;
	for(int i=1; i<=N; i++) {
		ans += mp[make(S[i], 3)];
		ans += mp[make(S[i], 5)];
		ans += mp[make(S[i], 9)];
		ans += mp[make(S[i], 6)];
		ans += mp[make(S[i], 10)];
		ans += mp[make(S[i], 12)];

		ans -= 3*mp[make(S[i], 1)];
		ans -= 3*mp[make(S[i], 2)];
		ans -= 3*mp[make(S[i], 4)];
		ans -= 3*mp[make(S[i], 8)];
	}
	return ans;
}

long long solve3() {
	long long ans = 0;
	for(int i=1; i<=N; i++) {
		ans += mp[make(S[i], 14)];
		ans += mp[make(S[i], 13)];
		ans += mp[make(S[i], 11)];
		ans += mp[make(S[i], 7)];

		ans -= 2*mp[make(S[i], 3)];
		ans -= 2*mp[make(S[i], 5)];
		ans -= 2*mp[make(S[i], 9)];
		ans -= 2*mp[make(S[i], 6)];
		ans -= 2*mp[make(S[i], 10)];
		ans -= 2*mp[make(S[i], 12)];

		ans += 3*mp[make(S[i], 1)];
		ans += 3*mp[make(S[i], 2)];
		ans += 3*mp[make(S[i], 4)];
		ans += 3*mp[make(S[i], 8)];
	}
	return ans;
}

int main() {
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> N >> D;
	for(int i=1; i<=N; i++) {
		cin >> S[i];
		for(int j=1; j<16; j++) ++mp[make(S[i], j)];
	}
	for(auto& it: mp) --it.second;
	long long ans = 0;
	if(D == 1) cout << solve1() / 2;
	if(D == 2) cout << solve2() / 2;
	if(D == 3) cout << solve3() / 2;
	if(D == 4) cout << (1LL*N*(N-1) - solve1() - solve2() - solve3()) / 2;
	return 0;
}

Compilation message

pin.cpp: In function 'int main()':
pin.cpp:75:12: warning: unused variable 'ans' [-Wunused-variable]
  long long ans = 0;
            ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2424 KB Output is correct
2 Correct 9 ms 2424 KB Output is correct
3 Correct 9 ms 2296 KB Output is correct
4 Correct 53 ms 3320 KB Output is correct
5 Correct 65 ms 3448 KB Output is correct
6 Correct 81 ms 3320 KB Output is correct
7 Correct 68 ms 3320 KB Output is correct
8 Correct 70 ms 3320 KB Output is correct
9 Correct 117 ms 3268 KB Output is correct
10 Correct 161 ms 3320 KB Output is correct
11 Correct 88 ms 3320 KB Output is correct
12 Correct 171 ms 3320 KB Output is correct
13 Correct 109 ms 3320 KB Output is correct
14 Correct 145 ms 3320 KB Output is correct
15 Correct 269 ms 3320 KB Output is correct
16 Correct 140 ms 9352 KB Output is correct
17 Correct 372 ms 11972 KB Output is correct
18 Correct 486 ms 11352 KB Output is correct
19 Correct 527 ms 11576 KB Output is correct
20 Correct 662 ms 11956 KB Output is correct