QAQ~
请问各位dalao这种算法空间复杂度是O(n)吗?
orz
#include <iostream>
using namespace std;
typedef long long ll;
#define endl '\n'
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll n, m, A[105][2], i, j, ans;
//我好像发现了一个空间复杂度O(n)的算法...
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
n = read(), m = read();
for (i = 1; i <= n; ++i)
if (i & 1)
for (j = 1; j <= m; ++j)
if (read())A[j][1] = min(A[j][0], min(A[j - 1][0], A[j - 1][1])) + 1, ans = max(ans, A[j][1]);
else A[j][1] = 0;
else
for (j = 1; j <= m; ++j)
if (read())A[j][0] = min(A[j][1], min(A[j - 1][0], A[j - 1][1])) + 1, ans = max(ans, A[j][0]);
else A[j][0] = 0;
cout<<ans<<'\n';
}