Skip to content

Commit 1581cd8

Browse files
committed
atcoder/abc076C
1 parent 38762bf commit 1581cd8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

atcoder/abc076/C/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
string const NOP = "UNRESTORABLE";
7+
string S, T;
8+
9+
bool solve(vector<char>& W, int s) {
10+
for (int i = 0; i < s; ++i) {
11+
if (W[i] == '?') W[i] = 'a';
12+
}
13+
for (int i = 0; i < T.size(); ++i) {
14+
if (W[s+i] == '?') {
15+
W[s+i] = T[i];
16+
}
17+
if (W[s+i] != T[i]) return false;
18+
}
19+
for (int i = s + T.size(); i < S.size(); ++i) {
20+
if (W[i] == '?') W[i] = 'a';
21+
}
22+
return true;
23+
}
24+
25+
string solve() {
26+
for (int i = S.size() - T.size(); i >= 0; --i) {
27+
vector<char> W(S.begin(), S.end());
28+
if (solve(W, i)) return string(W.begin(), W.end());
29+
}
30+
return NOP;
31+
}
32+
33+
int main() {
34+
ios_base::sync_with_stdio(false);
35+
cin.tie(0); cout.tie(0);
36+
37+
cin >> S >> T;
38+
cout << solve() << endl;
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)