int main(void) { std::ios_base::sync_with_stdio (false); size_t n; cin >> n >> ws; vvs graph(n, vs()); dfs_num.resize(n, 0); parent.resize(n, -1); finished = false; a = b = c = -1; string line; for (size_t line_cnt = 0; line_cnt < n; line_cnt++) { getline(cin, line); for (size_t char_cnt = 0; char_cnt < n; char_cnt++) { if (line.at(char_cnt) == '1') graph[line_cnt].push_back(char_cnt); } } for (size_t counter = 0; counter < n; counter++) if (!dfs_num[counter]) dfs(graph, counter); if (a >= 0) cout << a+1 << " " << b+1 << " " << c+1 << endl; else cout << -1 << endl; return 0; }
int main(int argc, char **argv){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; string s; int n; bool first=true; while(t--){ if(!first) cout<<'\n'; else first=false; cin>>s; n=s.size(); v.clear(); sum.clear(); v.resize(n); sum.resize(n,vi(n,0)); v[0]=s; for(int i=1;i<n;++i)cin>>v[i]; for(int i=0;i<n;++i) for(int j=0;j<n;++j){ sum[i][j]=(v[i][j]-'0'); if(i>0) sum[i][j]+=sum[i-1][j]; if(j>0) sum[i][j]+=sum[i][j-1]; if(i>0 && j>0) sum[i][j]-=sum[i-1][j-1]; } int largest=0,sumhere; /*for(int i=0;i<n;++i) for(int j=0;j<n;++j)cout<<sum[i][j]<<(j==n-1?'\n':' ');*/ for(int i=0;i<n;++i)for(int j=0;j<n;++j) for(int p=i;p<n;++p)for(int q=j;q<n;++q){ //cout<<"("<<i<<","<<j<<") . "<<"("<<p<<","<<q<<")"<<endl; sumhere=sum[p][q]; if(i>0) sumhere-=sum[i-1][q]; if(j>0) sumhere-=sum[p][j-1]; if(i>0 && j>0) sumhere+=sum[i-1][j-1]; if(v[i][j]=='1' && sumhere==(p-i+1)*(q-j+1)) largest=max(largest,sumhere); } cout<<largest<<'\n'; } return 0; }
int main(int argc, char **argv){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--){ cin>>c>>r; v.resize(r); memset(d,-1,sizeof(d)); memset(vis,0,sizeof(vis)); for(int i=0;i<r;++i)cin>>v[i]; bool udah=false; for(int i=0;i<r && !udah;++i) for(int j=0;j<c && !udah;++j) if(v[i][j]=='.'){ //cout<<i<<' '<<j<<'\n'; x=i; y=j; d[i][j]=0; dfs(i,j); udah=true; } //cout<<x<<' '<<y<<'\n'; memset(d,-1,sizeof(d)); memset(vis,0,sizeof(vis)); d[x][y]=0; dfs(x,y); //cout<<x<<' '<<y<<'\n'; cout<<"Maximum rope length is "<<d[x][y]<<".\n"; } return 0; }