社区讨论
dalao能否找下错
P3015[USACO11FEB] Best Parenthesis S参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo21dzwd
- 此快照首次捕获于
- 2023/10/23 06:24 2 年前
- 此快照最后确认于
- 2023/11/03 06:47 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
int n, head = 0, ans, a[100005], q[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (!a[i])
{
q[++head] = a[i];
}
else
{
if (a[i] == 1 && !q[head])
{
q[head] = 2;
ans++;
if (q[head - 1] != 1 && q[head])
{
q[head - 1] += q[head--];
}
}
else if (a[i] == 1 && q[head] && q[head] != 1 && q[head - 1] == 0)
{
q[head - 1] = 2;
head -= 1;
ans *= 2;
}
if (q[head] && q[head] != 1 && q[head - 1] != 1 && q[head - 1])
{
q[head - 1] = q[head--];
}
}
}
cout << ans;
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...