The standard looks like two points?
I preprocessed the tag a bit and then enumerated t from 1 to N, because for each t, if s exists, then S is unique, so enumerate T.
Determine if T is legal, direct violence, will time out
I do not know whether the standard idea is the same as mine, perhaps the standard is not marked but two points to find
However, my time complexity is more excellent, n (1+1/2+1/3+ ... 1/n) =n*lnn's approach
#include <iostream> #include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <vector> #include <algorithm >using namespace Std;struct ans{int s,t; Ans () {}ans (int a,int b) {s=a;t=b;} BOOL Operator < (Ans x) Const{return s!=x.s?s<x.s:t<x.t;}}; Vector<ans>ans;int in[100010];int as[100010];int ap[200010];int bs[100010];int bp[200010];int n;void maketable ( {int I,x,y;x=y=0;memset (ap,-1,sizeof (AP)), Memset (Bp,-1,sizeof (BP)), for (i=0;i<n;i++) {if (in[i]==1) ap[++x]=i; Elsebp[++y]=i;as[i]=x;bs[i]=y;}} int isOK (int s) {int t1,t2,x,y;t1=t2=s;x=y=0;while (1) {if (ap[t1]==-1&&bp[t2]==-1) return 0;if (ap[t1]==n-1 &&bp[t2]==-1) {++x;return x<=y?0:x;} if (ap[t1]==-1&&bp[t2]==n-1) {++y;return y<=x?0:y;} if (bp[t2]==-1| | (Ap[t1]!=-1&&ap[t1]<bp[t2])) {t2=bs[ap[t1]]+s;t1+=s;x++;} else if (ap[t1]==-1| | (Bp[t2]!=-1&&ap[t1]>bp[t2])) {T1=as[bp[t2]]+s;t2+=s;y++;} Elsereturn 0;}} int main () {int i,t,m;scanf ("%d", &n), for (i=0;i<n;i++) scanf ("%d", In+i), maketable (); for (i=1;i<=n;i++) {t= isOK (i); if (t!=0) ans.push_back (ans (t,i));} Sort (Ans.begin (), Ans.end ()), m=ans.size ();p rintf ("%d\n", M), for (i=0;i<m;i++) printf ("%d%d\n", ans[i].s,ans[i].t );}
D. Tennis Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
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 andT 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 MA TCH 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 andT for the GI Ven match is also lost. The players now wonder what values ofs andT 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 andT corresponds to the given Record.
Output
In the first, line print a, number K -the number of options for numberss andT.
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.
Sample Test (s) Input
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
Codeforces Round #283 (Div. 2) D. Tennis Game