B. Mammoth's Genome Decoding

Codeforces
IDCF747B
Time1000ms
Memory256MB
Difficulty
implementationstrings
English · Original
Chinese · Translation
Formal · Original
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain _s_. Each nucleotide is coded with a capital letter of English alphabet: '_A_', '_C_', '_G_' or '_T_'. Unrecognized nucleotides are coded by a question mark '_?_'. Thus, _s_ is a string consisting of letters '_A_', '_C_', '_G_', '_T_' and characters '_?_'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. ## Input The first line contains the integer _n_ (4 ≤ _n_ ≤ 255) — the length of the genome. The second line contains the string _s_ of length _n_ — the coded genome. It consists of characters '_A_', '_C_', '_G_', '_T_' and '_?_'. ## Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "_\===_" (without quotes). [samples] ## Note In the first example you can replace the first question mark with the letter '_A_', the second question mark with the letter '_G_', the third question mark with the letter '_T_', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
[{"iden":"statement","content":"伯兰国猛犸基因组解码工作即将完成!\n\n剩余的唯一任务之一是恢复已发现序列 #cf_span[s] 中无法识别的核苷酸。每个核苷酸用一个大写英文字母编码:'_A_'、'_C_'、'_G_' 或 '_T_'。无法识别的核苷酸用问号 '_?_' 表示。因此,#cf_span[s] 是由字母 '_A_'、'_C_'、'_G_'、'_T_' 和字符 '_?_' 组成的字符串。\n\n已知在伯兰国解码的猛犸基因组中,四种类型核苷酸的数量必须相等。\n\n你的任务是解码基因组,将每个无法识别的核苷酸替换为四种类型之一,使得四种类型核苷酸的数量相等。\n\n第一行包含整数 #cf_span[n] (#cf_span[4 ≤ n ≤ 255]) —— 基因组的长度。\n\n第二行包含长度为 #cf_span[n] 的字符串 #cf_span[s] —— 编码的基因组。它由字符 '_A_'、'_C_'、'_G_'、'_T_' 和 '_?_' 组成。\n\n如果可以解码基因组,请输出解码后的结果。如果有多个答案,输出任意一个即可。如果无法解码,请输出三个等号:\"_===_\"(不含引号)。\n\n在第一个例子中,你可以将第一个问号替换为字母 '_A_',第二个问号替换为 '_G_',第三个问号替换为 '_T_',此时基因组中每种核苷酸均出现两次。\n\n在第二个例子中,基因组已经正确解码,每种核苷酸恰好出现一次。\n\n在第三个和第四个例子中,无法解码基因组。 \n\n"},{"iden":"input","content":"第一行包含整数 #cf_span[n] (#cf_span[4 ≤ n ≤ 255]) —— 基因组的长度。第二行包含长度为 #cf_span[n] 的字符串 #cf_span[s] —— 编码的基因组。它由字符 '_A_'、'_C_'、'_G_'、'_T_' 和 '_?_' 组成。"},{"iden":"output","content":"如果可以解码基因组,请输出解码后的结果。如果有多个答案,输出任意一个即可。如果无法解码,请输出三个等号:\"_===_\"(不含引号)。"},{"iden":"examples","content":"输入8AG?C??CT输出AGACGTCT输入4AGCT输出AGCT输入6????G?输出===输入4AA??输出==="},{"iden":"note","content":"在第一个例子中,你可以将第一个问号替换为字母 '_A_',第二个问号替换为 '_G_',第三个问号替换为 '_T_',此时基因组中每种核苷酸均出现两次。在第二个例子中,基因组已经正确解码,每种核苷酸恰好出现一次。在第三个和第四个例子中,无法解码基因组。 "}] ```json [{"iden":"statement","content":"伯兰国猛犸基因组解码工作即将完成!\n\n剩余的唯一任务之一是恢复已发现序列 #cf_span[s] 中无法识别的核苷酸。每个核苷酸用一个大写英文字母编码:'_A_'、'_C_'、'_G_' 或 '_T_'。无法识别的核苷酸用问号 '_?_' 表示。因此,#cf_span[s] 是由字母 '_A_'、'_C_'、'_G_'、'_T_' 和字符 '_?_' 组成的字符串。\n\n已知在伯兰国解码的猛犸基因组中,四种类型核苷酸的数量必须相等。\n\n你的任务是解码基因组,将每个无法识别的核苷酸替换为四种类型之一,使得四种类型核苷酸的数量相等。\n\n第一行包含整数 #cf_span[n] (#cf_span[4 ≤ n ≤ 255]) —— 基因组的长度。\n\n第二行包含长度为 #cf_span[n] 的字符串 #cf_span[s] —— 编码的基因组。它由字符 '_A_'、'_C_'、'_G_'、'_T_' 和 '_?_' 组成。\n\n如果可以解码基因组,请输出解码后的结果。如果有多个答案,输出任意一个即可。如果无法解码,请输出三个等号:\"_===_\"(不含引号)。\n\n在第一个例子中,你可以将第一个问号替换为字母 '_A_',第二个问号替换为 '_G_',第三个问号替换为 '_T_',此时基因组中每种核苷酸均出现两次。\n\n在第二个例子中,基因组已经正确解码,每种核苷酸恰好出现一次。\n\n在第三个和第四个例子中,无法解码基因组。 \n\n"},{"iden":"input","content":"第一行包含整数 #cf_span[n] (#cf_span[4 ≤ n ≤ 255]) —— 基因组的长度。第二行包含长度为 #cf_span[n] 的字符串 #cf_span[s] —— 编码的基因组。它由字符 '_A_'、'_C_'、'_G_'、'_T_' 和 '_?_' 组成。"},{"iden":"output","content":"如果可以解码基因组,请输出解码后的结果。如果有多个答案,输出任意一个即可。如果无法解码,请输出三个等号:\"_===_\"(不含引号)。"},{"iden":"examples","content":"输入8AG?C??CT输出AGACGTCT输入4AGCT输出AGCT输入6????G?输出===输入4AA??输出==="},{"iden":"note","content":"在第一个例子中,你可以将第一个问号替换为字母 '_A_',第二个问号替换为 '_G_',第三个问号替换为 '_T_',此时基因组中每种核苷酸均出现两次。在第二个例子中,基因组已经正确解码,每种核苷酸恰好出现一次。在第三个和第四个例子中,无法解码基因组。 "}] ```
Let $ n $ be the length of the genome string $ s $, and let $ s \in \{A, C, G, T, ?\}^n $. Let $ c_X $ denote the count of nucleotide $ X \in \{A, C, G, T\} $ in $ s $, and let $ q $ denote the number of question marks (`?`) in $ s $. Define the target count for each nucleotide: $$ t = \frac{n}{4} $$ **Constraints:** - $ n \equiv 0 \pmod{4} $ (otherwise, impossible) - For each $ X \in \{A, C, G, T\} $, $ c_X \leq t $ - $ q = 4t - (c_A + c_C + c_G + c_T) $ **Objective:** If the above constraints are satisfied, replace each `?` with one of $ A, C, G, T $ such that the final count of each nucleotide is exactly $ t $. Output any such valid replacement. Otherwise, output `===`. --- **Formal Statement:** Given: - $ n \in \mathbb{Z} $, $ 4 \leq n \leq 255 $ - $ s \in \{A, C, G, T, ?\}^n $ Define: - $ t = n / 4 $ - $ c_X = |\{ i \mid s[i] = X \}| $ for $ X \in \{A, C, G, T\} $ - $ q = |\{ i \mid s[i] = ? \}| $ **Feasibility Conditions:** 1. $ n \bmod 4 \neq 0 $ → impossible 2. $ \exists X \in \{A, C, G, T\} $ such that $ c_X > t $ → impossible 3. $ q \neq 4t - \sum_{X \in \{A,C,G,T\}} c_X $ → impossible **If feasible:** Find a string $ s' \in \{A, C, G, T\}^n $ such that: - $ s'[i] = s[i] $ if $ s[i] \neq ? $ - $ s'[i] \in \{A, C, G, T\} $ if $ s[i] = ? $ - $ |\{ i \mid s'[i] = X \}| = t $ for all $ X \in \{A, C, G, T\} $ Output any such $ s' $. Otherwise, output `===`.
Samples
Input #1
8
AG?C??CT
Output #1
AGACGTCT
Input #2
4
AGCT
Output #2
AGCT
Input #3
6
????G?
Output #3
\===
Input #4
4
AA??
Output #4
\===
API Response (JSON)
{
  "problem": {
    "name": "B. Mammoth's Genome Decoding",
    "description": {
      "content": "The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain _s_. Each nucleotide is coded with a capit",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF747B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The process of mammoth's genome decoding in Berland comes to its end!\n\nOne of the few remaining tasks is to restore unrecognized nucleotides in a found chain _s_. Each nucleotide is coded with a capit...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "[{\"iden\":\"statement\",\"content\":\"伯兰国猛犸基因组解码工作即将完成!\\n\\n剩余的唯一任务之一是恢复已发现序列 #cf_span[s] 中无法识别的核苷酸。每个核苷酸用一个大写英文字母编码:'_A_'、'_C_'、'_G_' 或 '_T_'。无法识别的核苷酸用问号 '_?_' 表示。因此,#cf_span[s] 是由字母 '_A_'、'_C_'、'_G_'、'_T_'...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ n $ be the length of the genome string $ s $, and let $ s \\in \\{A, C, G, T, ?\\}^n $.\n\nLet $ c_X $ denote the count of nucleotide $ X \\in \\{A, C, G, T\\} $ in $ s $, and let $ q $ denote the numbe...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments