Advertisement
Korotkodul

N6 v2

Dec 17th, 2022
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. vector <string> res;
  51.  
  52. int k, n, m;
  53. vector <vector <bool> > was;
  54. bool ok(int i, int j) {
  55.     return i >= 0 && j >= 0 && i < 16 * n && j < 8 * m && !was[i][j] && res[i][j] == '1';
  56. }
  57.  
  58. int cnt;
  59.  
  60. vector <int> d = {-1, 0, 1};
  61.  
  62.  
  63. void dfs(int i, int j) {
  64.     was[i][j] = 1;
  65.     cnt++;
  66.     for (int dx: d) {
  67.         for (int dy: d) {
  68.             if (dx == 0 && dy == 0) {
  69.                 continue;
  70.             }
  71.             int x = i + dx;
  72.             int y = j + dy;
  73.             if (ok(x, y)) {
  74.                 dfs(x, y);
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80. bool sh = 0;
  81.  
  82. int main() {
  83.     ios::sync_with_stdio(0);
  84.     cin.tie(0);
  85.     cout.tie(0);
  86.     vector <string> r;
  87.  
  88.     cin >> k >> n >> m;
  89.     vector <vector <string> > als(k, vector <string> (16));
  90.     for (int go = 0; go < k; ++go) {
  91.         for (int i = 0; i < 16; ++i) {
  92.             string s; cin >> s;
  93.             als[go][i] = s;
  94.         }
  95.     }
  96.     /*cout << "\n";
  97.     for (auto v: als) {
  98.         cvs(v);
  99.         cout << "\n";
  100.     }*/
  101.     vector <vector <int> > scr(n, vector <int> (m));
  102.     for (int i = 0; i < n; ++i) {
  103.         for (int j = 0; j < m; ++j) {
  104.             cin >> scr[i][j];
  105.             scr[i][j]--;
  106.         }
  107.     }
  108.     res.assign(n * 16, "");
  109.     int id=-1;
  110.     for (int i = 0; i < n; ++i) {
  111.             for (int p = 0; p < 16; ++p) {
  112.                 id++;
  113.                 for (int j = 0; j < m; ++j) {
  114.                     res[id] += als[ scr[i][j] ][p];
  115.                 }
  116.  
  117.             }
  118.     }
  119.  
  120.     if (sh) cvs(res);
  121.     int ans = 0;
  122.     for (int i = 0; i < n * 16; ++i) {
  123.         for (int j = 0 ; j < m * 8; ++j) {
  124.             cnt = 0;
  125.             dfs(i, j);
  126.             ans = max(ans, cnt);
  127.         }
  128.     }
  129.     cout << ans;
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement