Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- #pragma GCC optimize 03
- #pragma GCC optimize("unroll-loops")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef std::pair<int, int> pii;
- typedef std::pair<char, char> pcc;
- typedef std::pair<ll, ll> pll;
- typedef tree<int,
- null_type,
- less<int>,
- rb_tree_tag,
- tree_order_statistics_node_update> ordered_set;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define file_in_out freopen("file.in", "r", stdin); freopen("file.out", "w", stdout);
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (int)x.size()
- #define fi first
- #define se second
- template<typename T>
- istream& operator>>(istream &in, vector<T> &v) {
- for (auto &it : v) {
- in >> it;
- }
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, const vector<T> &v) {
- for (auto &it : v) {
- out << it << " ";
- }
- return out;
- }
- template<typename T1, typename T2>
- istream& operator>>(istream &in, pair<T1, T2> &v) {
- in >> v.fi >> v.se;
- return in;
- }
- template<typename T1, typename T2>
- ostream& operator<<(ostream &out, const pair<T1, T2> &v) {
- out << v.fi << " " << v.se;
- return out;
- }
- vector<vector<int>> g;
- vector<int> mt;
- vector<char> used;
- void resize_all(int n, int m) {
- g.resize(n);
- mt.resize(m, -1);
- used.resize(n);
- }
- bool dfs(int v) {
- if (used[v]) return false;
- used[v] = true;
- for (auto u : g[v]) {
- if (mt[u] == -1 || dfs(mt[u])) {
- mt[u] = v;
- return true;
- }
- }
- return false;
- }
- int main() {
- fast
- // file_in
- int m;
- cin >> m;
- string s;
- cin >> s;
- vector<string> cub(m);
- cin >> cub;
- int n = sz(s);
- resize_all(m, n);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- if (find(all(cub[j]), s[i]) != s.end()) {
- g[j].push_back(i);
- }
- }
- }
- for (int i = 0; i < m; ++i) {
- if (dfs(i)) {
- for (auto &el : used) el = 0;
- }
- }
- vector<int> mts;
- for (int i = 0; i < n; ++i) {
- if (mt[i] != -1) {
- mts.push_back(mt[i] + 1);
- }
- }
- if (sz(mts) != n) {
- cout << "NO" << '\n';
- return 0;
- }
- cout << "YES" << '\n';
- cout << mts << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement