Advertisement
clown1337

Untitled

Dec 19th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <set>
  5. #include <map>
  6. #include <unordered_map>
  7. #include <unordered_set>
  8. #include <queue>
  9. #include <deque>
  10. #include <stack>
  11. #include <cmath>
  12. #include <numeric>
  13. #include <algorithm>
  14. #include <random>
  15. #include <fstream>
  16. #include <iomanip>
  17. #include <limits>
  18. #include <bitset>
  19. #include <ostream>
  20. #include <sstream>
  21. #include <cstring>
  22. #include <cassert>
  23. using namespace std;
  24. /// Pragmas ///
  25. //#pragma GCC optimize("Ofast")
  26. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
  27. //#pragma GCC optimize("unroll-loops")
  28. /// typedef ///
  29. typedef long long ll;
  30. typedef long double ld;
  31. typedef unsigned long long ull;
  32. #define int long long
  33.  
  34. ll gcd(ll a, ll b) {
  35. return b ? gcd(b, a % b) : a;
  36. }
  37.  
  38. const int N = 90000;
  39. int dx[4] = {-1, 0, 0, 1};
  40. int dy[4] = {0, -1, 1, 0};
  41.  
  42. vector <vector <bool>> used(N, vector <bool> (N));
  43. vector <string> s;
  44. int temp = 1;
  45. bool e = false;
  46.  
  47. void dfs(int x, int y, int cnt, int n, int m) {
  48. used[x][y] = true;
  49. if (x == 0 || x == 16 * n -1 || y == 0 || y == 8*m-1) e = true;
  50. for (int i = 0; i < 4; ++i) {
  51. int curX = x + dx[i];
  52. int curY = y + dy[i];
  53. if (curX >= 0 && curX < 16*n && curY >= 0 && curY < 8 * m) {
  54. if (!used[curX][curY] && s[curX][curY] == '0') {
  55. temp = max(temp, cnt+1);
  56. dfs(curX, curY, cnt+1, n, m);
  57. }
  58. }
  59. }
  60. temp = max(temp, cnt+1);
  61. }
  62.  
  63. void solve() {
  64. int k, n, m;
  65. cin >> k >> n >> m;
  66. vector <vector <string>> a(k, vector <string> (16));
  67. for (int i = 0; i < k; ++i) {
  68. for (int j = 0; j < 16; ++j) {
  69. cin >> a[i][j];
  70. }
  71. }
  72. vector <vector <int>> b(n, vector <int>(m));
  73. for (int i = 0; i < n; ++i) {
  74. for (int j = 0; j < m; ++j) {
  75. cin >> b[i][j];
  76. b[i][j]--;
  77. }
  78. }
  79. for (int i = 0; i < n; ++i) {
  80. for (int j = 0; j < 16; ++j) {
  81. string t = a[b[i][0]][j];
  82. for (int l = 0; l < m; ++l) {
  83. t += (a[b[i][l]][j]);
  84. }
  85. s.push_back(t);
  86. }
  87. }
  88. int ans = 0;
  89. for (int i = 0; i < s.size(); ++i) {
  90. for (int j = 0; j < s[i].size(); ++j) {
  91. if (s[i][j] == '0' && !used[i][j]) {
  92. dfs(i, j, 1, n, m);
  93. if (!e) {
  94. ans = max(ans, temp);
  95. }
  96. e = false;
  97. temp = 1;
  98. }
  99. }
  100. }
  101. cout << ans << '\n';
  102.  
  103. }
  104.  
  105. signed main() {
  106. ios_base::sync_with_stdio(false);
  107. cin.tie(NULL);
  108. // freopen("","r",stdin);
  109. // freopen("","w",stdout);
  110. int t = 1;// cin >> t;
  111. while (t--) solve();
  112. return 0;
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement