何も考えずに実装する。やるだけ。
class InternetSecurity {
public:
vector <string> determineWebsite(vector <string> A, vector <string> K, vector <string> D, int T)
{
vector< vector<string> > ks(A.size());
for (int i = 0; i < K.size(); ++i) {
istringstream iss(K[i]);
for (string s; iss >> s; ks[i].push_back(s)) ;
sort(ks[i].begin(), ks[i].end());
}
vector<string> v;
vector<string> tmp = A;
for (int i = 0; i < A.size(); ++i) {
int cnt = 0;
for (int j = 0; j < D.size(); ++j) {
cnt += binary_search(ks[i].begin(), ks[i].end(), D[j]);
}
if (T <= cnt) {
D.insert(D.end(), ks[i].begin(), ks[i].end());
sort(D.begin(), D.end());
D.erase(unique(D.begin(), D.end()), D.end());
v.push_back(A[i]);
A.erase(A.begin() + i);
ks.erase(ks.begin() + i);
i = -1;
}
}
sort(v.begin(), v.end());
vector<string> ret;
for (int i = 0; i < tmp.size(); ++i) {
if (binary_search(v.begin(), v.end(), tmp[i])) {
ret.push_back(tmp[i]);
}
}
return ret;
}
};
0 件のコメント :
コメントを投稿