Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <stack>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- ifstream cin("alpinistii.in");
- ofstream cout("alpinistii.out");
- const int NMAX = 205;
- int v[NMAX][NMAX], L[NMAX], R[NMAX], f[NMAX], cnt, m;
- void flood(int i, int j)
- {
- if(v[i][j])
- return;
- v[i][j] = 1;
- cnt++;
- flood(i+1, j);
- flood(i-1, j);
- flood(i, j+1);
- flood(i, j-1);
- }
- int maxarea()
- {
- int j, maxim = 0;
- stack <int> st;
- st.push(0);
- f[0] = -1;
- for(j = 1; j <= m; j++)
- {
- while(f[j] <= f[st.top()])
- st.pop();
- L[j] = st.top();
- st.push(j);
- }
- while(!st.empty())
- st.pop();
- st.push(m+1);
- f[m+1] = -1;
- for(j = m; j >= 1; j--)
- {
- while(f[j] <= f[st.top()])
- st.pop();
- R[j] = st.top();
- st.push(j);
- }
- for(j = 1; j <= m; j++)
- maxim = max(maxim, f[j] * (R[j] - L[j] - 1));
- return maxim;
- }
- int main()
- {
- int n, i, j, cer, maxim = 0, ans = 0;
- cin >> cer >> n >> m;
- for(i = 1; i <= n; i++)
- for(j = 1; j <= m; j++)
- cin >> v[i][j];
- for(i = 0; i <= n+1; i++)
- v[i][0] = v[i][m+1] = 1;
- for(j = 0; j <= m+1; j++)
- v[0][j] = v[n+1][j] = 1;
- if(cer == 1)
- {
- for(i = 1; i <= n; i++)
- for(j = 1; j <= m; j++)
- {
- if(!v[i][j])
- {
- cnt = 0;
- flood(i, j);
- maxim = max(maxim, cnt);
- }
- }
- cout << maxim;
- return 0;
- }
- for(i = 1; i <= n; i++)
- {
- for(j = 1; j <= m; j++)
- {
- if(!v[i][j])
- f[j]++;
- else
- f[j] = 0;
- }
- ans = max(ans, maxarea());
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement