File tree Expand file tree Collapse file tree 2 files changed +98
-0
lines changed
Expand file tree Collapse file tree 2 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2068F.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-24
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #define endl ' \n '
14+
15+ #define maxn 200005
16+
17+ vector<int > rec[26 ];
18+ string s[maxn];
19+
20+ void solve (void ) {
21+ int n;
22+ cin >> n;
23+ for (int i = 1 ; i <= n; i++) {
24+ cin >> s[i];
25+ reverse (s[i].begin (), s[i].end ());
26+ rec[s[i].back () - ' a' ].push_back (i);
27+ }
28+ string t, ans;
29+ cin >> t;
30+ reverse (t.begin (), t.end ());
31+ while (n) {
32+ int p = -1 ;
33+ for (int x = 0 ; x < 26 ; x++)
34+ if (t.back () - ' a' != x && !rec[x].empty ()) p = x;
35+ if (p == -1 ) {
36+ p = t.back () - ' a' ;
37+ t.pop_back ();
38+ if (t.empty ()) return cout << " NO" << endl, void ();
39+ }
40+ ans.push_back (p + ' a' );
41+ vector<int > rrec;
42+ rrec.swap (rec[p]);
43+ for (auto idx : rrec) {
44+ s[idx].pop_back ();
45+ if (s[idx].empty ())
46+ n--;
47+ else
48+ rec[s[idx].back () - ' a' ].push_back (idx);
49+ }
50+ }
51+ cout << " YES" << endl << ans << endl;
52+ return ;
53+ }
54+
55+ int main () {
56+ ios::sync_with_stdio (false ), cin.tie (nullptr );
57+
58+ int _ = 1 ;
59+ while (_--) solve ();
60+
61+ return 0 ;
62+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2068J.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-24
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #define endl ' \n '
14+
15+ void solve (void ) {
16+ int n;
17+ string s;
18+ cin >> n >> s;
19+ int cnt[2 ] = {0 , 0 };
20+ for (int i = 0 ; i < n; i++) cnt[s[i] == ' R' ]++;
21+ if (cnt[0 ] & 1 ) return cout << " NO" << endl, void ();
22+ for (int i = 0 ; i < (cnt[0 ] >> 1 ); i++)
23+ if (s[i] == ' R' || s[s.size () - 1 - i] == ' W' ) return cout << " NO" << endl, void ();
24+ cout << " YES" << endl;
25+ return ;
26+ }
27+
28+ int main () {
29+ ios::sync_with_stdio (false ), cin.tie (nullptr );
30+
31+ int _ = 1 ;
32+ cin >> _;
33+ while (_--) solve ();
34+
35+ return 0 ;
36+ }
You can’t perform that action at this time.
0 commit comments