1+ package c287 ;
2+
3+ import java .nio .charset .StandardCharsets ;
4+ import java .util .Scanner ;
5+
6+ public class Abc287_d {
7+ public static void main (String [] args ) {
8+ Scanner scanner = new Scanner (System .in , StandardCharsets .UTF_8 );
9+ String s = scanner .next ();
10+ String t = scanner .next ();
11+ System .out .println (solve (s , t ));
12+ }
13+
14+ private static String solve (String s , String t ) {
15+ int n = s .length ();
16+ int m = t .length ();
17+
18+ // pre[i] 表示前缀长度为 i 时,前缀是否 match
19+ boolean [] pre = new boolean [m + 1 ];
20+ pre [0 ] = true ;
21+ for (int i = 1 ; i <= m ; i ++) {
22+ char ch1 = s .charAt (i - 1 );
23+ char ch2 = t .charAt (i - 1 );
24+ pre [i ] = pre [i - 1 ] && (ch1 == ch2 || ch1 == '?' || ch2 == '?' );
25+ if (!pre [i ]) break ;
26+ }
27+
28+ // suf[i] 表示后缀长度为 i 时,后缀是否 match
29+ boolean [] suf = new boolean [m + 1 ];
30+ suf [0 ] = true ;
31+ for (int i = 1 ; i <= m ; i ++) {
32+ char ch1 = s .charAt (n - i );
33+ char ch2 = t .charAt (m - i );
34+ suf [i ] = suf [i - 1 ] && (ch1 == ch2 || ch1 == '?' || ch2 == '?' );
35+ if (!suf [i ]) break ;
36+ }
37+
38+ String [] res = new String [m + 1 ];
39+ for (int i = 0 ; i < m + 1 ; i ++) {
40+ res [i ] = pre [i ] && suf [m - i ] ? "Yes" : "No" ;
41+ }
42+ return String .join (System .lineSeparator (), res );
43+ }
44+ }
45+ /*
46+ D - Match or Not
47+ https://atcoder.jp/contests/abc287/tasks/abc287_d
48+
49+ 预处理 前后缀
50+ */
0 commit comments