Submission #637850

# Submission time Handle Problem Language Result Execution time Memory
637850 2022-09-03T12:11:05 Z TAMREF 흑백 이미지 찾기 (kriii3_G) C++17
0 / 101
10000 ms 8208 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define bi_pc __builtin_popcount
#define bi_pcll __builtin_popcountll
#define bi_tz __builtin_ctz
#define bi_tzll __builtin_ctzll
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef TAMREF
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#endif
using namespace std;
using ll = long long; using lf = long double; 
using pii = pair<int,int>; using ppi = pair<int,pii>;
using pll = pair<ll,ll>; using pff = pair<lf,lf>;
using ti = tuple<int,int,int>;
using base = complex<double>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v){return u = max(u, v);}
template <typename T>
inline T umin(T& u, T v){return u = min(u, v);}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m, r, c;
using L = __int128_t;
const ll tmods[4] = {1000000007, 1000000009, 998244353, 7 << 26 | 1};

int main(){
  fio;
  cin >> n >> m;
  auto a = vector<vector<ll>>(n, vector<ll>(m));
  for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
  cin >> r >> c;
  auto b = vector<vector<ll>>(r, vector<ll>(c));
  for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) cin >> b[i][j];

  int ans = 0;
  L bsum = 0, b2sum = 0;
  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
        bsum += b[i][j];
        b2sum += b[i][j] * b[i][j];
    }
  }
  for(int i = 0; i + r - 1 < n; i++) {
    for(int j = 0; j + c - 1 < m; j++) {
        debug("i = %d, j = %d, ans = %d\n", i, j, ans);
        L asum = 0, a2sum = 0, absum = 0;
        for(int k = i; k < i + r; k++) {
            for(int l = j; l < j + c; l++) {
                asum += a[k][l];
                a2sum += a[k][l] * a[k][l];
                absum += a[k][l] * b[k-i][l-j];
            }
        }
        ll bvar = (b2sum * r * c - bsum * bsum);
        ll cov = (absum * r * c - asum * bsum);
        ll avar =(a2sum * r * c - asum * asum);
        ll diff = (cov * cov - avar * bvar);
        if(!diff) ++ans;
    }
  }
  cout << ans << '\n';
}

Compilation message

G.cpp: In function 'int main()':
G.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
G.cpp:57:9: note: in expansion of macro 'debug'
   57 |         debug("i = %d, j = %d, ans = %d\n", i, j, ans);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1827 ms 8184 KB Output is correct
2 Correct 7154 ms 8208 KB Output is correct
3 Execution timed out 10078 ms 8188 KB Time limit exceeded
4 Halted 0 ms 0 KB -