Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- void fastIO()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- }
- int mx,n,m,a[110][110];
- void solve(int i,int j,int depth,int last)
- {
- if(i==0 || j==0 || i>n || j>m || a[i][j]>=last){
- mx = max(mx,depth);
- return;
- }
- solve(i+1,j,depth+1,a[i][j]);
- solve(i,j+1,depth+1,a[i][j]);
- solve(i-1,j,depth+1,a[i][j]);
- solve(i,j-1,depth+1,a[i][j]);
- }
- int main()
- {
- //read();
- //write();
- fastIO();
- int t;
- cin>>t;
- while(t--){
- string s;
- cin>>s>>n>>m;
- cout<<s<<": ";
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- cin>>a[i][j];
- }
- }
- mx = 0;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- solve(i+1,j,1,a[i][j]);
- solve(i,j+1,1,a[i][j]);
- solve(i-1,j,1,a[i][j]);
- solve(i,j-1,1,a[i][j]);
- }
- }
- cout<<mx<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement