Official

C - Route Map Editorial by KoD


\(T_i \, (1 \leq i \leq M)\) からなる文字列の集合を \(T\) とおきます。 \(i \, (1 \leq i \leq N)\) 番目の答えが Yes であることは、\(S_i\)\(T\) に属することと同値です。

C++ であれば std::set、Python であれば set を用いて実装することができます。

実装例 (C++) :

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n), t(m);
    for (string& x : s) {
        cin >> x;
    }
    for (string& x : t) {
        cin >> x;
    }
    set<string> rapid(t.begin(), t.end());
    for (const string& x : s) {
        cout << (rapid.count(x) ? "Yes" : "No") << '\n';
    }
}

実装例 (Python)

n, m = map(int, input().split())
s = input().split()
t = set(input().split())
for x in s:
    print("Yes" if x in t else "No")

posted:
last update: