本题考试使就是想不出非暴力算法。
考完后得知暴力的复杂度是O(t*(n/t))=O(n) ..我一直以为是O(n^2)...
我说为什么有人5minAC,,说多了都是泪
解法:
显然t确定s就确定了,暴力枚举t,然后扫一遍,记得先预处理使得能在O(1)查找1局比赛
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,n1=0,n2=0;
int f[MAXN],g[MAXN]; // f/g win'game num
int a[MAXN],b[MAXN]; // f/g win f[i] game until ith game end
vector<pair<int,int> > ans;
int main()
{
// freopen("Tennis.in","r",stdin);
// freopen(".out","w",stdout);
MEMI(f) MEMI(g)
cin>>n;
For(i,n)
{
int t;
scanf("%d",&t);
if (t&1) f[++n1]=i;
else g[++n2]=i;
a[i]=n1,b[i]=n2;
}
For(t,n)
{
bool flag=0;
int s1=0,s2=0,cur1=0,cur2=0;
for(int cur=0;cur<=n;)
{
int x,y;
if (cur1+t>n1&&cur2+t>n2) {flag=1;break;}
int now=min(x=f[cur1+t],y=g[cur2+t]);
if (x<y) s1++;else s2++;
cur1=a[now],cur2=b[now];
if (now==n)
{
if (x<y&&s1<s2) flag=1; //x win the last game but totally y win
if (x>y&&s1>s2) flag=1; //y win the last game but totally x win
if (s1==s2) flag=1; //impossible for role
break;
}
cur=now;
}
if (!flag) ans.push_back(make_pair(max(s1,s2),t));
}
sort(ans.begin(),ans.end());
printf("%d\n",ans.size());
Rep(i,ans.size()) printf("%d %d\n",ans[i].first,ans[i].second);
return 0;
}