View Code of Problem 17

#include <stdio.h>
#include <string.h>

int n,m;
int visit[60000][60000];
int map[60000][60000];
int max=0;
int maxcnt=0;
int climb(int a,int b,int cnt)
{
	if(map[a][b]==max)
	{
		if(cnt>maxcnt)
		{
			maxcnt=cnt;
		}
		return 1;
	}
	else
	{
		if(a+1<n&&visit[a+1][b]!=1&&map[a+1][b]>map[a][b])
		{
			visit[a][b]=1;
			climb(a+1,b,cnt+1);
			visit[a][b]=0;
		}
			if(a-1>=0&&visit[a-1][b]!=1&&map[a-1][b]>map[a][b])
		{
			visit[a][b]=1;
			climb(a-1,b,cnt+1);
			visit[a][b]=0;
		}
			if(b+1<m&&visit[a][b+1]!=1&&map[a][b+1]>map[a][b])
		{
			visit[a][b]=1;
			climb(a,b+1,cnt+1);
			visit[a][b]=0;
		}
			if(b-1>=0&&visit[a][b-1]!=1&&map[a][b-1]>map[a][b])
		{
			visit[a][b]=1;
			climb(a,b-1,cnt+1);
			visit[a][b]=0;
		}
	}
	if(cnt>maxcnt)
	{
		maxcnt=cnt;
	}
}


int main()
{
	scanf("%d%d",&n,&m);
	int mini=0,minj=0,min=9999;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			scanf("%d",&map[i][j]);
			if(map[i][j]>max)
			{
				max=map[i][j];
			}
			if(map[i][j]<min)
			{
				min=map[i][j];
				mini=i;
				minj=j;
			}
		}
	}
	climb(mini,minj,0);
	printf("%d\n",maxcnt);
	
	
	
 } 
/*
Main.cc: In function 'int climb(int, int, int)':
Main.cc:50:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/usr/bin/ld: /tmp/ccpQFJBF.o: in function `climb(int, int, int)':
Main.cc:(.text+0x5c): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x6d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x9a): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0xe3): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x11c): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x176): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x19e): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text+0x1c2): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: /tmp/ccpQFJBF.o: in function `main':
Main.cc:(.text.startup+0x5): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccpQFJBF.o
/usr/bin/ld: Main.cc:(.text.startup+0xc): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
*/

Double click to view unformatted code.


Back to problem 17