Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // __________________
- // | ________________ |
- // || ____ ||
- // || /\ | ||
- // || /__\ | ||
- // || / \ |____ ||
- // ||________________||
- // |__________________|
- // \###################\
- // \###################\
- // \ ____ \
- // \_______\___\_______\
- // An AC a day keeps the doctor away.
- #pragma g++ optimize("Ofast")
- #pragma loop_opt(on)
- #include <bits/stdc++.h>
- #include <bits/extc++.h>
- #ifdef local
- #define debug(x) (cerr<<#x<<" = "<<(x)<<'\n')
- #else
- #define debug(x) ((void)0)
- #endif // local
- #define all(v) begin(v),end(v)
- #define siz(v) (ll(v.size()))
- #define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
- #define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
- #define pb emplace_back
- #define ff first
- #define ss second
- #define mem(v,x) memset(v,x,sizeof v)
- using namespace std;
- using namespace __gnu_pbds;
- typedef int64_t ll;
- typedef long double ld;
- typedef pair<ll,ll> pll;
- typedef pair<ld,ld> pld;
- template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
- template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
- template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
- constexpr ld PI = acos(-1), eps = 1e-5;
- constexpr ll N = 55, INF = 1e18, MOD = 998244353, K = 32, inf = 1e9;
- constexpr inline ll cdiv(ll x, ll m) { return x/m + (x<0 ^ m>0) && (x%m); } // ceiling divide
- //constexpr ll modpow(ll e,ll p,ll m=MOD) {ll r=1; for(;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r;}
- int n,m,a,b,S[N][N],T[N][N],ans[N][N];
- void sol() {
- cin >> n >> m;
- for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> S[i][j];
- cin >> a >> b;
- for(int i = 0; i < a; i++) for(int j = 0; j < b; j++) cin >> T[i][j];
- for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ans[i][j] = 0;
- for(int i = 0; i+a <= n; i++) for(int j = 0; j+b <= m; j++) if(!ans[i][j]){
- ans[i][j] = 1;
- for(int x = 0; x < a; x++) for(int y = 0; y < b; y++) if(T[x][y] != S[i+x][j+y]) ans[i][j] = 0;
- }
- for(int i = 0; i+b <= n; i++) for(int j = 0; j+a <= m; j++) if(!ans[i][j]){
- ans[i][j] = 1;
- for(int x = 0; x < b; x++) for(int y = 0; y < a; y++) if(T[y][x] != S[i+x][j+y]) ans[i][j] = 0;
- }
- for(int i = 0; i+a <= n; i++) for(int j = 0; j+b <= m; j++) if(!ans[i][j]){
- ans[i][j] = 1;
- for(int x = 0; x < a; x++) for(int y = 0; y < b; y++) if(T[x][b-1-y] != S[i+x][j+y]) ans[i][j] = 0;
- }
- for(int i = 0; i+b <= n; i++) for(int j = 0; j+a <= m; j++) if(!ans[i][j]){
- ans[i][j] = 1;
- for(int x = 0; x < b; x++) for(int y = 0; y < a; y++) if(T[a-1-y][x] != S[i+x][j+y]) ans[i][j] = 0;
- }
- //cout<<"===\n";
- //for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cout << ans[i][j] << " \n"[j==m-1];
- int res=0;
- for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) res += ans[i][j];
- cout<<res<<'\n';
- }
- signed main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- int t;
- cin >> t;
- while(t--) sol();
- }
Advertisement
Add Comment
Please, Sign In to add comment