Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. const int ZERO = 160 * 1280, NMAX = 88;
  3. std::bitset<2*ZERO+1> curr[NMAX], next[NMAX];
  4. int a[NMAX][NMAX], b[NMAX][NMAX], n, m;
  5. int main() {
  6.     std::cin >> n >> m;
  7.     for (int i = 1; i <= n; i++) {
  8.         for (int j = 1; j <= m; j++) {
  9.             std::cin >> a[i][j];
  10.         }
  11.     }
  12.     for (int i = 1; i <= n; i++) {
  13.         for (int j = 1; j <= m; j++) {
  14.             std::cin >> b[i][j];
  15.         }
  16.     }
  17.     curr[1][ZERO] = 1;
  18.     for (int i = 1; i <= n; i++) {
  19.         for (int j = 1; j <= m; j++) {
  20.             int delta = std::abs(a[i][j] - b[i][j]);
  21.             next[j] |= (next[j-1] << delta) | (next[j-1] >> delta);
  22.             next[j] |= (curr[j] << delta) | (curr[j] >> delta);
  23.         }
  24.         std::copy(next+1,next+m+1,curr+1);
  25.         std::fill(next+1,next+m+1, 0);
  26.     }
  27.     int answ = 1281;
  28.     for (int x = -1280; x <= 1280; x++) {
  29.         if (curr[m][x+ZERO]) {
  30.             answ = std::min(answ, std::abs(x));
  31.         }
  32.     }
  33.     std::cout << answ << std::endl;
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top