-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem88.cpp
More file actions
49 lines (41 loc) · 942 Bytes
/
problem88.cpp
File metadata and controls
49 lines (41 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
class StrongestSecretPair {
int n;
vector<string> words;
public:
void readInput() {
cin >> n;
cin.ignore();
words.resize(n);
for (int i = 0; i < n; ++i) {
getline(cin, words[i]);
}
}
void solve() {
vector<pair<int, int>> masks; // {bitmask, length}
for (string &word : words) {
int mask = 0;
for (char c : word) {
mask |= (1 << (c - 'a'));
}
masks.push_back({mask, word.size()});
}
int maxStrength = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if ((masks[i].first & masks[j].first) == 0) {
int strength = masks[i].second * masks[j].second;
maxStrength = max(maxStrength, strength);
}
}
}
cout << maxStrength << endl;
}
};
int main() {
StrongestSecretPair solver;
solver.readInput();
solver.solve();
return 0;
}