Official

C - AtCoder Cards Editorial by en_translator


If @ is not involved, the answer is Yes if the occurrences of each letter in \(S\) and \(T\) are equal, and No otherwise. With @, we similarly think if we can match the occurrences of each character by appropriately replacing @s.

We first find the numbers of @ in \(S\) and \(T\). Then, we count the occurrences for each character of atcoder in \(S\) and \(T\), and for each character \(c\), replace @ in the string containing less number of \(c\) with \(c\) (or instead of actually modifying the string, we can just increment the count). If you run out of @ during this process, the answer is No.

(This strategy is optimal because the string with less number of \(c\) should result in having at least same number of it than the other string in order to match the occurrences, while we should consume as few @ as possible.)

If we never ran out of @ during the process, and the occurrences of other characters are also the same, then the answer is Yes; otherwise the answer is No.

Sample code (Python)
Sample code (C)

posted:
last update: