Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <set>
- #include <map>
- #include <unordered_map>
- #include <unordered_set>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <cmath>
- #include <numeric>
- #include <algorithm>
- #include <random>
- #include <fstream>
- #include <iomanip>
- #include <limits>
- #include <bitset>
- #include <ostream>
- #include <sstream>
- #include <cstring>
- #include <cassert>
- using namespace std;
- /// Pragmas ///
- //#pragma GCC optimize("Ofast")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
- //#pragma GCC optimize("unroll-loops")
- /// typedef ///
- typedef long long ll;
- typedef long double ld;
- typedef unsigned long long ull;
- #define int long long
- ll gcd(ll a, ll b) {
- return b ? gcd(b, a % b) : a;
- }
- const int N = 90000;
- int dx[4] = {-1, 0, 0, 1};
- int dy[4] = {0, -1, 1, 0};
- vector <vector <bool>> used(N, vector <bool> (N));
- vector <string> s;
- int temp = 1;
- bool e = false;
- void dfs(int x, int y, int cnt, int n, int m) {
- used[x][y] = true;
- if (x == 0 || x == 16 * n -1 || y == 0 || y == 8*m-1) e = true;
- for (int i = 0; i < 4; ++i) {
- int curX = x + dx[i];
- int curY = y + dy[i];
- if (curX >= 0 && curX < 16*n && curY >= 0 && curY < 8 * m) {
- if (!used[curX][curY] && s[curX][curY] == '0') {
- temp = max(temp, cnt+1);
- dfs(curX, curY, cnt+1, n, m);
- }
- }
- }
- temp = max(temp, cnt+1);
- }
- void solve() {
- int k, n, m;
- cin >> k >> n >> m;
- vector <vector <string>> a(k, vector <string> (16));
- for (int i = 0; i < k; ++i) {
- for (int j = 0; j < 16; ++j) {
- cin >> a[i][j];
- }
- }
- vector <vector <int>> b(n, vector <int>(m));
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- cin >> b[i][j];
- b[i][j]--;
- }
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < 16; ++j) {
- string t = a[b[i][0]][j];
- for (int l = 0; l < m; ++l) {
- t += (a[b[i][l]][j]);
- }
- s.push_back(t);
- }
- }
- int ans = 0;
- for (int i = 0; i < s.size(); ++i) {
- for (int j = 0; j < s[i].size(); ++j) {
- if (s[i][j] == '0' && !used[i][j]) {
- dfs(i, j, 1, n, m);
- if (!e) {
- ans = max(ans, temp);
- }
- e = false;
- temp = 1;
- }
- }
- }
- cout << ans << '\n';
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- // freopen("","r",stdin);
- // freopen("","w",stdout);
- int t = 1;// cin >> t;
- while (t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement