dalao能否找下错
查看原帖
dalao能否找下错
557540
Celius楼主2023/7/31 11:20
#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;
}


2023/7/31 11:20
加载中...