CF1784E.Infinite Game

普及/提高-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing an infinite game consisting of sets. Each set consists of rounds. In each round, one of the players wins. The first player to win two rounds in a set wins this set. Thus, a set always ends with the score of 2:02:0 or 2:12:1 in favor of one of the players.

Let's call a game scenario a finite string ss consisting of characters 'a' and 'b'. Consider an infinite string formed with repetitions of string ss: ssssss \ldots Suppose that Alice and Bob play rounds according to this infinite string, left to right. If a character of the string ssssss \ldots is 'a', then Alice wins the round; if it's 'b', Bob wins the round. As soon as one of the players wins two rounds, the set ends in their favor, and a new set starts from the next round.

Let's define aia_i as the number of sets won by Alice among the first ii sets while playing according to the given scenario. Let's also define rr as the limit of ratio aii\frac{a_i}{i} as ii \rightarrow \infty. If r>12r \gt \frac{1}{2}, we'll say that scenario ss is winning for Alice. If r=12r = \frac{1}{2}, we'll say that scenario ss is tied. If r<12r \lt \frac{1}{2}, we'll say that scenario ss is winning for Bob.

You are given a string ss consisting of characters 'a', 'b', and '?'. Consider all possible ways of replacing every '?' with 'a' or 'b' to obtain a string consisting only of characters 'a' and 'b'. Count how many of them result in a scenario winning for Alice, how many result in a tied scenario, and how many result in a scenario winning for Bob. Print these three numbers modulo 998244353998\,244\,353.

爱丽丝和鲍勃正在进行一场无限轮次的比赛,比赛由若干局(set)组成。每一局包含若干轮(round)。在每一轮中,其中一名选手获胜。率先在单局中赢得两轮的选手即赢得该局。因此,每一局的最终比分必为 2:02:02:12:1,胜者为其中一方。

我们称一个比赛情形(game scenario)为一个仅由字符 'a''b' 构成的有限字符串 ss。考虑由该字符串 ss 无限重复构成的无限字符串:ssssss \ldots。假设爱丽丝与鲍勃按照该无限字符串从左至右进行每一轮比赛:若字符串 ssssss \ldots 中某一位是 'a',则爱丽丝赢得该轮;若是 'b',则鲍勃赢得该轮。一旦某位选手在当前局中赢得两轮,该局立即结束,胜者即为该局获胜方,并从下一轮开始新一局。

定义 aia_i 为按给定情形进行比赛时,前 ii 局中爱丽丝获胜的局数。再定义 rr 为比值 aii\frac{a_i}{i}ii \to \infty 时的极限。若 r>12r > \frac{1}{2},则称情形 ss 对爱丽丝有利(winning for Alice);若 r=12r = \frac{1}{2},则称情形 ss平局情形(tied);若 r<12r < \frac{1}{2},则称情形 ss 对鲍勃有利(winning for Bob)。

现给定一个由字符 'a''b''?' 组成的字符串 ss。考虑所有将每个 '?' 替换为 'a''b' 的方式,从而得到仅含 'a''b' 的字符串。统计其中有多少种替换方式使得所得情形对爱丽丝有利,多少种为平局情形,多少种对鲍勃有利。请输出这三个数值对 998244353998\,244\,353 取模的结果。

输入格式

The only line contains a single string ss (1s2001 \le |s| \le 200), consisting of characters 'a', 'b', and '?'.

唯一的一行包含一个字符串 ss1s2001 \le |s| \le 200),由字符 'a'、'b' 和 '?' 组成。

输出格式

Print three integers: how many ways result in a scenario winning for Alice, how many result in a tied scenario, and how many result in a scenario winning for Bob, modulo 998244353998\,244\,353.

输出三个整数:分别表示 Alice 获胜的情形数、平局的情形数、Bob 获胜的情形数,结果对 998244353998\,244\,353 取模。

输入输出样例

  • 输入#1

    ??

    输出#1

    1
    2
    1
  • 输入#2

    ?aa?b

    输出#2

    1
    3
    0
  • 输入#3

    a???ba

    输出#3

    4
    3
    1
  • 输入#4

    ????????

    输出#4

    121
    14
    121
  • 输入#5

    ba????a?a???abbb?

    输出#5

    216
    57
    239
  • 输入#6

    a????a??????b??abbababbbb?a?aaa????bb

    输出#6

    97833
    28387
    135924
  • 输入#7

    ??????????????a????????????????b?????

    输出#7

    484121060
    448940322
    484613337

说明/提示

In the first example, there are four ways to replace the question marks:

  • s=aas = \mathtt{aa}: Alice wins every set 2:02:0 — the scenario is winning for Alice;
  • s=abs = \mathtt{ab}: Alice and Bob win sets in turns, with the score of 2:12:1 each — the scenario is tied;
  • s=bas = \mathtt{ba}: Bob and Alice win sets in turns, with the score of 2:12:1 each — the scenario is tied;
  • s=bbs = \mathtt{bb}: Bob wins every set 2:02:0 — the scenario is winning for Bob.

在第一个例子中,有四种方式替换问号:

  • s=aas = \mathtt{aa}:爱丽丝每盘均以 2:02:0 获胜——该情形对爱丽丝有利;
  • s=abs = \mathtt{ab}:爱丽丝与鲍勃交替赢下各盘,比分为各 2:12:1——该情形为平局;
  • s=bas = \mathtt{ba}:鲍勃与爱丽丝交替赢下各盘,比分为各 2:12:1——该情形为平局;
  • s=bbs = \mathtt{bb}:鲍勃每盘均以 2:02:0 获胜——该情形对鲍勃有利。

输入解题思路,AI测评打分。不知道怎么写?

首页