Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <climits>
- #include <unordered_set>
- //#include <chrono>
- //#include <fstream>
- //#include <bits/stdc++.h>
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define x first
- #define y second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- typedef vector<int> veci;
- typedef vector<bool> vecb;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<bool>> vvb;
- const int INF_I = 1e9;
- const ll INF_LL = 1e18;
- vector<unordered_set<int>> vec;
- vector<bool> used;
- vector<int> p;
- bool dfs(int v) {
- if (used[v])
- return false;
- used[v] = true;
- for (int i : vec[v])
- if (p[i] == -1 || dfs(p[i])) {
- p[i] = v;
- return true;
- }
- return false;
- }
- int main() {
- /*ifstream cin("in.txt");
- ofstream cout("out.txt");
- auto start_time = chrono::high_resolution_clock::now();*/
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- string tem;
- cin >> tem;
- int len = tem.size();
- if (n < len) {
- cout << "NO\n";
- return 0;
- }
- p.assign(n, -1);
- vector<list<int>> vec_ch(26);
- for (int i = 0; i < len; i++)
- vec_ch[tem[i] - 'A'].eb(i);
- vec.assign(len, unordered_set<int>());
- for (int i = 0; i < n; i++)
- for (int j = 0; j < 6; j++) {
- char ch;
- cin >> ch;
- for (int cur : vec_ch[ch - 'A'])
- vec[cur].emplace(i);
- }
- int cnt = 0;
- for (int i = 0; i < n; i++) {
- used.assign(len, 0);
- cnt += (int)dfs(i);
- }
- if (cnt < len) {
- cout << "NO\n";
- return 0;
- }
- cout << "YES\n";
- vector<int> res(len);
- for (int i = 0; i < n; i++)
- res[p[i]] = i + 1;
- for (int i : res)
- cout << i << " ";
- /*auto end_time = chrono::high_resolution_clock::now();
- chrono::duration<double> duration = end_time - start_time;
- cout << duration.count() << "\n";
- cin.close();
- cout.close();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment