Codeforces Round #283 (Div. 2) D. Tennis Game

Source: Internet
Author: User
Tags integer numbers

Petya and Gena love playing table tennis. A single match was played according to the following Rules:a match consists of multiple sets, each set consists of MULTIPL E serves. Each serve was 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 is being set to 0. As soon as one of the players wins the total ofs sets, he wins the match and the match are over. Heres and T is some positive integer numbers.

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

Petya and Gena has found a record of an old match. Unfortunately, the sequence of serves in the record isn ' t divided to sets and numberss and T for the G Iven match is also lost. The players now wonder what values ofs and T might be. Can determine all the possible options?

Input

The first line contains a single integer n -the length of the sequence in games (1?≤? N? ≤?105).

The second line contains n space-separated integersai. Ifai? =?1, then thei-th serve is won by Petya, if a i=?2, then the i-th serve is won by Gena.

It is not guaranteed, at least one, option for numberss and T corresponds to the given Record.

Output

In the first, line print a, number K -the number of options for numberss and T.

In each of the following K lines Print II integerssi andti -the option for numberss and T. Print the options in the order of increasingsi, and for equalsi -in The order of increasingTI.

Examplesinput
51 2 1) 2 1
Output
21 33 1
Input
41 1 1 1
Output
31 42 24 1
Input
41 2 1 2
Output
0
Input
82 1 2 1 1 1 1 1
Output
31 62 36 1


Test instructions: Give you a series of race scores, ask you the possible s and t have several groups.


Analysis: The winner of the last game must be the winner of the S, the first thought of this after the intention to push backwards, and then found that the situation behind is not ok .... The positive solution is an enumeration of T, followed by an O (n/t) to determine if there is a character

The condition of S.


#include <cstdio> #include <iostream> #include <algorithm>using namespace Std;int n,num,a[200001],f[ 3][200001],f[3][200002],tot[3];struct Thing{int s,t;friend bool operator < (thing a,thing b) {if (A.S = = B.S) return A.T < B.t;return a.s < B.S;}} Ans[100001];int Main () {scanf ("%d", &n), for (int i = 1;i <= n;i++) {scanf ("%d", &a[i]), f[a[i]][i] = ++tot[a[i]]; F[3-a[i]][i] = f[3-a[i]][i-1]; F[a[i]][tot[a[i]] = i;} for (int i = 1;i <= n;i++) {int now[3]={0,0,0},pos = 1;bool flag = False;while (True) {if (pos = = n+1) {flag = True;break;} i F (F[a[pos]][f[a[pos]][pos] + i-1] = = 0 && F[3-a[pos]][f[3-a[pos]][pos] + i] = = 0) break;if (f[a[pos]][f[a[pos]][p OS] + i-1] = = 0 | | F[a[pos]][f[a[pos]][pos] + i-1]-pos + 1>= 2*i) pos = F[3-a[pos]][f[3-a[pos]][pos] + i] + 1;else pos = f[a[pos]][f[a [POS]] [POS] + i-1] + 1;now[a[pos-1]]++;} if (flag && Now[a[n]] > Now[3-a[n]) {ans[++num].s = now[a[n]];ans[num].t = i;}} Sort (ans+1,ans+1+num); cout<<num< <endl;for (int i = 1;i <= num;i++) cout<<ans[i].s<< "" <<ans[i].t<<endl;} 



Codeforces Round #283 (Div. 2) D. Tennis Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.