#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
#define m_p make_pair
const int N = 1003;
int p[N], ch[N];
int fi(int x)
{
if (x == p[x])
return x;
return p[x] = fi(p[x]);
}
void kpc(int x, int y)
{
x = fi(x);
y = fi(y);
if (ch[x] > ch[y])
{
ch[x] += ch[y];
p[y] = x;
}
else
{
ch[y] += ch[x];
p[x] = y;
}
}
bool c[N];
int tt;
int t[N];
void ubd(int x)
{
if (c[x - 1] && c[x + 1])
{
int tv = t[fi(x - 1)] + t[fi(x + 1)] + 1;
kpc(x - 1, x);
kpc(x, x + 1);
t[fi(x)] = tv;
tt = max(tt, tv);
}
else if (c[x - 1])
{
int tv = t[fi(x - 1)] + 1;
kpc(x - 1, x);
t[fi(x)] = tv;
tt = max(tt, tv);
}
else if (c[x + 1])
{
int tv = t[fi(x + 1)] + 1;
kpc(x, x + 1);
t[fi(x)] = tv;
tt = max(tt, tv);
}
else
{
int tv = 1;
t[fi(x)] = tv;
tt = max(tt, tv);
}
c[x] = true;
}
int n, m, k;
int a[N][N];
void clr()
{
for (int i = 1; i <= m; ++i)
{
c[i] = false;
p[i] = i;
ch[i] = 1;
t[i] = 0;
}
tt = 0;
}
queue<int> q[N];
int xx[N][N];
int stg(int x)
{
for (int j = 1; j <= m; ++j)
{
if (a[n][j] < x)
xx[n][j] = n;
else
xx[n][j] = N;
for (int i = n - 1; i >= 1; --i)
{
if (a[i][j] < x)
xx[i][j] = i;
else
xx[i][j] = xx[i + 1][j];
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
clr();
for (int j = 1; j <= m; ++j)
{
if (xx[i][j] == N)
ubd(j);
else
{
if (xx[i][j] != i)
q[xx[i][j]].push(j);
}
}
for (int ii = n; ii >= i; --ii)
{
while (!q[ii + 1].empty())
{
ubd(q[ii + 1].front());
q[ii + 1].pop();
}
ans = max(ans, (ii - i + 1) * tt);
}
}
return ans;
}
vector<int> v;
int main()
{
//freopen("input2.txt", "r", stdin);
//freopen("minimum.in", "r", stdin);
//freopen("minimum.out", "w", stdout);
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
scanf("%d", &a[i][j]);
v.push_back(a[i][j]);
}
}
sort(v.begin(), v.end());
int l = 0, r = v.size() - 1;
while ((r - l) > 4)
{
int m = v[(l + r) / 2];
if (stg(m) >= k)
l = (l + r) / 2;
else
r = (l + r) / 2;
}
for (int i = r; i >= l; --i)
{
int m = v[i];
if (stg(m) >= k)
{
cout << m << " " << stg(m) << endl;
return 0;
}
}
return 0;
}
Compilation message
burrow.cpp: In function 'int main()':
burrow.cpp:140:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
burrow.cpp:145:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1144 KB |
Output is correct |
4 |
Correct |
2 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
9 ms |
1912 KB |
Output is correct |
9 |
Correct |
14 ms |
2936 KB |
Output is correct |
10 |
Correct |
20 ms |
3192 KB |
Output is correct |
11 |
Correct |
50 ms |
3960 KB |
Output is correct |
12 |
Correct |
39 ms |
5460 KB |
Output is correct |
13 |
Correct |
25 ms |
2552 KB |
Output is correct |
14 |
Correct |
104 ms |
5484 KB |
Output is correct |
15 |
Correct |
128 ms |
5488 KB |
Output is correct |
16 |
Correct |
114 ms |
5996 KB |
Output is correct |
17 |
Correct |
78 ms |
6740 KB |
Output is correct |
18 |
Correct |
281 ms |
10120 KB |
Output is correct |
19 |
Correct |
457 ms |
10600 KB |
Output is correct |
20 |
Correct |
667 ms |
15584 KB |
Output is correct |
21 |
Correct |
671 ms |
17732 KB |
Output is correct |
22 |
Correct |
932 ms |
22752 KB |
Output is correct |
23 |
Correct |
904 ms |
22496 KB |
Output is correct |
24 |
Correct |
777 ms |
14556 KB |
Output is correct |
25 |
Correct |
579 ms |
15916 KB |
Output is correct |