Funny or Scary?

시간 제한2초메모리 제한2048 MB

요약
완전 그래프의 미정 간선에 F 또는 S를 배정해 어떤 순열에서도 같은 종류가 ceil(3n/4)개를 넘게 연속하지 않도록 한다.
난이도

어려움10점 중 8점

유형
그래프, 그리디, 조합론, 완전 탐색
정답자
아직 제출이 없습니다

문제

You are designing a new video game. It has nn scenarios, which the player may play in any order, but each scenario must be played exactly once. When a player switches from a scenario to another scenario, the game shows a specially crafted transition video to make it all feel part of one big story. This video is specific to a pair of scenarios, but not to their order, in other words, the video playing when switching from scenario aa to scenario bb is the same as the video playing when switching from scenario bb to scenario aa. Therefore, you need to create n(n−1)2\frac{n(n-1)}{ 2} different transition videos, one for each possible pair of different scenarios.

Each transition video can be either funny or scary. It is boring to see too many funny videos or too many scary videos in a row. Therefore, your goal is to create the videos in such a way that no matter in which order does the player approach the scenarios, they will never see more than ⌈3n4⌉\left\lceil \frac{3n}{4} \right\rceil transition videos of the same type in a row.

You have already come up with ideas for at most ⌊n2⌋\left\lfloor \frac{n}{2} \right\rfloor of the transition videos, and therefore already know if those will be funny or scary. Now you need to choose funny or scary for all other transition videos in such a way that the above requirement is satisfied.

입력

The first line contains a single integer nn (2≤n≤242 ≤ n ≤ 24) — the number of scenarios in the game.

The next nn lines describe the partial transition video plan. Each of those lines contains nn characters. The jj-th character of the ii-th line corresponds to the transition video between the ii-th and the jj-th scenarios. It will be F if the corresponding transition video will be funny, S if the corresponding transition video will be scary, ? if the corresponding transition video is still undecided, or . if i=ji = j.

It is guaranteed that the ii-th character of the jj-th line and the jj-th character of the ii-th line will be the same for all ii and jj. It is guaranteed that at most ⌊n2⌋\left\lfloor \frac{n}{ 2} \right\rfloor (nn divided by 22, rounded down) transition videos will already be decided, in other words, that at most 2⌊n2⌋2\left\lfloor \frac{n}{ 2} \right\rfloor characters in the input will be F or S.

출력

Print nn lines describing the full transition video plan in the same format as the input. Each of those lines must contain nn characters. The jj-th character of the ii-th line must be F if the corresponding transition video is funny, S if the corresponding transition video is scary, or . if i=ji = j.

Each ? character from the input must be replaced with either F or S, and all other characters from the input must remain unchanged. It must still hold that the ii-th character of the jj-th line and the jj-th character of the ii-th line are the same for all ii and jj.

For each permutation of the nn scenarios, it must hold that the transition videos corresponding to playing the scenarios in this order do not have more than ⌈3n4⌉\left\lceil \frac{3n}{4} \right\rceil (3n3n divided by 44, rounded up) videos of the same type consecutively.

If there are multiple solutions, print any of them. It can be proven that for all inputs satisfying the constraints of this problem a solution always exists.

예제2

  1. 예제 1

    입력
    5
    .?F??
    ?.???
    F?.S?
    ??S.?
    ????.
    
    예상 출력
    .FFFF
    F.FFF
    FF.SF
    FFS.F
    FFFF.
    
  2. 예제 2

    입력
    12
    .???????????
    ?.??????????
    ??.?????????
    ???.????????
    ????.???????
    ?????.??????
    ??????.?????
    ???????.????
    ????????.???
    ?????????.??
    ??????????.?
    ???????????.
    
    예상 출력
    .SSSFFSSSSFS
    S.SFFSFSFFFS
    SS.SFFFSSSFS
    SFS.FFSSSSFS
    FFFF.FFFFFSF
    FSFFF.SFFSFF
    SFFSFS.SSSFS
    SSSSFFS.SSFS
    SFSSFFSS.SFS
    SFSSFSSSS.FS
    FFFFSFFFFF.F
    SSSSFFSSSSF.