求助!单调栈WA了三个点,不知道哪里出错了
  • 板块P4147 玉蟾宫
  • 楼主LShadows
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/10/28 23:05
  • 上次更新2023/11/4 02:02:06
查看原帖
求助!单调栈WA了三个点,不知道哪里出错了
469870
LShadows楼主2021/10/28 23:05
#include <bits/stdc++.h>
using namespace std; 
#define endl "\n"
#define int long long
#define rep(i,x,y) for(int i=x;i<=y;i++)
const int N=1000+10;
int t,m,n;
int heights[N][N],vis[N];
vector<int> vec;
signed main()
{
	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin>>n>>m;
 	memset(heights,0,sizeof(heights));
 	rep(i,1,n)
 		rep(j,1,m)
 		{
 			char ch;
 			cin>>ch;
 			if(ch=='F')
 				heights[i][j]=heights[i-1][j]+1;
		}
 	rep(i,1,n)
 		heights[i][m+1]=-1;	
	int res=0;
	stack<int> st;
	rep(i,1,n)
	{
		
		rep(j,1,m+1)
	    {
	        while(st.size()&&heights[i][st.top()]>heights[i][j]) 
	        {
	        	int val=st.top();
	            int height=heights[i][val];
	            int width;
	            st.pop();
	            width=j-val;
	            res=max(res,height*width);
	            //cout<<width<<" "<<height<<endl;
	    	}
	        st.push(j);
		}
		while(st.size()) st.pop();
	}
	cout<<res*3<<endl; 
 	return 0;
}

WA在第7、8、9三个点了,不知道哪里出错了,求各位大佬指点。

2021/10/28 23:05
加载中...