BZOJ挂了
数据下载
如果用 AC自动机/KMP 可以得到
Θ
(
n
3
)
\Theta(n^3)
Θ(n3) 的做法
这是万万不行的
而 bitset 并不支持相关操作
我们先不要考虑算法,,
考虑操作的时候会出现什么情况
显然
要染黑所有点就要让所有点被染黑
所以挑出所有左上角的点就可以了
Θ
(
n
2
)
\Theta(n^2)
Θ(n2)
,,
很遗憾我下不下来测试数据 不过起码上面的思路应该是没有问题的
细节还挺多。。
update:用黑暗爆炸oj测了一发 test5就tle了
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, q, a, b, Lstot, Target, adjx, adjy;
char tmpchar;
const int MAXN = 1005;
pair<int, int> Lst[MAXN*MAXN];
bool Image[MAXN][MAXN], Print[MAXN][MAXN]; int Ojbk;
bool PntChecked[MAXN][MAXN];
bool WorkAnswer()
{
for (int stx, sty, i = 1; i <= Lstot; ++i)
{
stx=Lst[i].first, sty=Lst[i].second;
if (!PntChecked[stx][sty])
{
for (int j = 1; j <= a; ++j)
{
for (int k = 1; k <= b; ++k)
{
if (stx - adjx + j > n || sty - adjy + k > m)
{
if(Print[j][k]) return 0;
else continue;
}
if (Image[stx-adjx+j][sty-adjy+k] < Print[j][k]) { return 0;}
if (Print[j][k]&&(!PntChecked[stx-adjx+j][sty-adjy+k]))
PntChecked[stx-adjx+j][sty-adjy+k] = 1, ++Ojbk;
}
}
}
}
if (Ojbk!=Target) return 0;
return 1;
}
int main()
{
ios::sync_with_stdio(false);
cin >> q;
while (q--)
{
Lstot = 0;
adjx = 0; adjy = 0;
Ojbk = 0; Target = 0;
cin >> n >> m >> a >> b;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
Print[i][j] = PntChecked[i][j] = 0;
cin >> tmpchar;
if ( Image[i][j] = (tmpchar=='x') ) ++Target, Lst[++Lstot] = make_pair(i, j);
}
}
for (int i = 1; i <= a; ++i)
{
for (int j = 1; j <= b; ++j)
{
cin >> tmpchar;
Print[i][j] = (tmpchar=='x') ;
if ( Print[i][j] && (!adjx) ) adjx = i, adjy = j;
}
}
cout<<(WorkAnswer()?"TAK":"NIE")<<endl;
}
return 0;
}