比赛 |
noi pro 模拟赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
AAAB(无题面) |
最终得分 |
100 |
用户昵称 |
胡嘉兴 |
运行时间 |
0.073 s |
代码语言 |
C++ |
内存使用 |
12.71 MiB |
提交时间 |
2018-10-26 20:59:25 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 1e6+7;
char s[N];
vector<int> vec, pos;
int match[N], sum[N], pre[N];
int main()
{
int ans, res, tot = 0, n;
freopen("AAAB.in", "r", stdin);
freopen("AAAB.out", "w", stdout);
scanf("%s", s+1);
n = strlen(s+1);
for(int i = 1; i <= n; i++)
{
if(s[i]==')'&&vec.size()&&vec.back()==0)
{
pre[pos.back()] = i;
match[pos.back()] = match[i] = ++tot;;
vec.pop_back();
pos.pop_back();
}
else if(s[i]==')'&&vec.size())
{
vec.push_back(1);
pos.push_back(i);
}
else if(s[i]=='(')
{
vec.push_back(0);
pos.push_back(i);
}
}
ans = 0;
vec.clear();
for(int i = 1; i <= n; i++)
{
sum[i] = sum[i-1]+(match[i]==0);
}
for(int i = 1; i <= n; i++)
{
if(pre[i]&&sum[pre[i]]-sum[i-1]==0)
{
vec.push_back(i);
vec.push_back(i=pre[i]);
}
}
for(int i = 0; i < vec.size(); i++)
{
int j = i+2;
while(j<vec.size()&&vec[j]==vec[j-1]+1)
{
j += 2;
}
j--;
if(vec[j]-vec[i]+1>ans)
{
res = 1;
ans = vec[j]-vec[i]+1;
}
else if(vec[j]-vec[i]+1==ans)
{
res++;
}
i = j;
}
if(!ans)
{
res = 1;
}
printf("%d %d\n", ans, res);
return 0;
}