codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

825D.md (1707B)


      1 Source: https://codeforces.com/problemset/problem/825/D
      2 
      3 D. Suitable Replacement
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
     22 
     23 Suitability of string *s* is calculated by following metric:
     24 
     25 Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings *s*, you choose the one with the largest number of non-intersecting occurrences of string *t*. Suitability is this number of occurrences.
     26 
     27 You should replace all '?' characters with small Latin letters in such a way that the suitability of string *s* is maximal.
     28 
     29 Input
     30 
     31 The first line contains string *s* (1 ≤ |*s*| ≤ 106).
     32 
     33 The second line contains string *t* (1 ≤ |*t*| ≤ 106).
     34 
     35 Output
     36 
     37 Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
     38 
     39 If there are multiple strings with maximal suitability then print any of them.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 ?aa?  
     47 ab
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 baab
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 ??b?  
     60 za
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 azbz
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 abcd  
     73 abacaba
     74 ```
     75 
     76 Output
     77 
     78 ```
     79 abcd
     80 ```
     81 
     82 Note
     83 
     84 In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.
     85 
     86 In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
     87 
     88 In the third example there are no '?' characters and the suitability of the string is 0.