CF496D.Tennis Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers.

To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets.

Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options?

佩佳和杰纳喜欢打乒乓球。一场单场比赛按以下规则进行:一场比赛包含多局,每局包含多个发球。每个发球由其中一名选手赢得,该选手得一分。一旦某名选手得分达到 tt 分,他即赢得该局;随后下一局开始,双方选手的得分均重置为 0。一旦某名选手总共赢得 ss 局,他即赢得整场比赛,比赛结束。其中 ss 和 tt 均为正整数。

为了增加趣味性,佩佳和杰纳在每场比赛前都会选定新的 ss 和 tt 值。此外,为了留作历史记录,他们还会完整记录每场比赛的过程:即对每个发球,都记下获胜者。发球获胜者按时间顺序依次记录。在记录中,一旦某名选手在一局中得分达到 tt 分,则该局立即结束;一旦某名选手赢得的局数总计达到 ss 局,则整场比赛立即结束。

佩佳和杰纳找到了一场旧比赛的记录。遗憾的是,该记录中的发球序列并未划分成局,且该场比赛所用的 ss 和 tt 值也已丢失。现在两位选手想知道:哪些 ss 和 tt 的取值是可能的?你能确定所有可能的选项吗?

输入格式

The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 105).

The second line contains n space-separated integers a__i. If a__i = 1, then the i-th serve was won by Petya, if a__i = 2, then the i-th serve was won by Gena.

It is not guaranteed that at least one option for numbers s and t corresponds to the given record.

第一行包含一个整数 nn —— 比赛序列的长度(1 ≤ n ≤ 1051 \leq n \leq 10^5)。

第二行包含 nn 个用空格分隔的整数 aia_i。若 ai=1a_i = 1,则第 ii 次发球由 Petya 赢得;若 ai=2a_i = 2,则第 ii 次发球由 Gena 赢得。

不能保证存在至少一组数 ss 和 tt 与给定记录对应。

输出格式

In the first line print a single number k — the number of options for numbers s and t.

In each of the following k lines print two integers s__i and t__i — the option for numbers s and t. Print the options in the order of increasing s__i, and for equal s__i — in the order of increasing t__i.

第一行输出一个整数 kk —— 满足条件的数对 ss 和 tt 的方案数。

接下来的 kk 行中,每行输出两个整数 sis_i 和 tit_i —— 一组满足条件的 ss 和 tt。所有方案需按 sis_i 升序排列;当 sis_i 相等时,按 tit_i 升序排列。

输入输出样例

  • 输入#1

    5
    1 2 1 2 1

    输出#1

    2
    1 3
    3 1
  • 输入#2

    4
    1 1 1 1

    输出#2

    3
    1 4
    2 2
    4 1
  • 输入#3

    4
    1 2 1 2

    输出#3

    0
  • 输入#4

    8
    2 1 2 1 1 1 1 1

    输出#4

    3
    1 6
    2 3
    6 1

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

首页