Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _____ __ __ __ __ __
- | \ | | | | | | | | /\ | |
- | |\ \ | | | | | | | | / \ | |
- | | \ \ | | | | | |____| | / /\ \ | |
- | | \ \ | | | | | ____ | / /__\ \ | |
- | | \ \ | | | | | | | | / ______ \ | |
- | | \ \| | | | | | | | / / \ \ | |_________
- |__| \_____| |__| |__| |__| /_/ \_\ |____________|
- */
- #include <bits/stdc++.h>
- #define sf(a) scanf("%d",&a)
- #define sfl(a) scanf("%lld",&a)
- #define sff(a,b) scanf("%d %d",&a,&b)
- #define sffl(a,b) scanf("%lld %lld",&a,&b)
- #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
- #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
- #define sffff(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
- #define sffffl(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
- #define sfffff(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
- #define sfffffl(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
- #define MEM(a,b) memset(a, (b), sizeof(a))
- #define sfc(a) scanf("%c",&a)
- #define pb(a) push_back(a)
- #define X first
- #define Y second
- #define sz(x) x.size()
- #define pii pair<int,int>
- #define pli pair<long long int,int>
- #define mp(a,b) make_pair(a,b)
- #define fr(i,x,n) for(int i=x;i<n;i++)
- #define rfr(i,x,n) for(int i=x;i>n;i--)
- #define LCM(a, b) ((a)*((b)/GCD(a,b)))
- template<typename T>T Abs(T a) {
- return (a < 0 ? -a : a);
- }
- template<typename T>T MAX(T a, T b) {
- return (a > b ? a : b);
- }
- template<typename T>T MIN(T a, T b) {
- return (a < b ? a : b);
- }
- template<typename T>T GCD(T a, T b) {
- if (b == 0)return a;
- return GCD(b, a % b);
- }
- template<typename T>inline void read(T &x) {
- T f = 1;
- char c;
- x = 0;
- for (c = getchar(); c < '0' || c > '9'; c = getchar())if (c == '-')f = -1;
- for (; c >= '0' && c <= '9'; c = getchar())x = x * 10 + c - '0';
- x *= f;
- }
- using fl = float;
- using db = double;
- using ll = long long;
- using ull = unsigned long long;
- const int mx = 10005;
- const int inf = 99999999;
- const int intlim = 2147483648;
- const db PI = acos(-1); //3.14159265358979323846264338328
- /*------------------------------Graph Moves----------------------------*/
- //const int fx[]={+1,-1,+0,+0};
- //const int fy[]={+0,+0,+1,-1};
- const int fx[] = { +0, +0, +1, -1, -1, +1, -1, +1}; // Kings Move
- const int fy[] = { -1, +1, +0, +0, +1, +1, -1, -1}; // Kings Move
- //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
- //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
- /*---------------------------------------------------------------------*/
- using namespace std;
- string str[26];
- int vis[25][25];
- int n, c = 0;
- void dfs(int x, int y) {
- if (x < 0 || y < 0 || x >= n || y >= n)return;
- c++, vis[x][y] = 1;
- for (int i = 0; i < 8; ++i)
- if (str[x + fx[i]][y + fy[i]] == '1' && !vis[x + fx[i]][y + fy[i]])
- dfs(x + fx[i], y + fy[i]);
- }
- int main() {
- int t, z = 1;
- cin >> t;
- while (t--) {
- str[0].clear();
- c = 0;
- for (int i = 0; i < 25; i++)for (int j = 0; j < 25; ++j)vis[i][j] = 0;
- getchar();
- cin >> str[0];
- n = sz(str[0]);
- for (int i = 1; i < n; ++i)cin >> str[i];
- int ans = 0;
- for (int i = 0; i < n; ++i)cout << str[i] << endl;
- if (n != 0)
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j) {
- c = 0;
- if (str[i][j] == '1' && vis[i][j] == 0)dfs(i, j), ans = MAX(ans, c);
- }
- printf("%d\n", ans);
- if (t)printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement