This was good problem for people interested in pure algorithm and tweaking. I had to spend some time (read 2 hours) to come up with something that would satisfy the 256 bytes constraint. Luckily I happen to be a friend of a gifted individual (read one whose got an ACC) who had solved this problem before. With his tips I was able to to get an ACC finally :) So here it goes
#define f(a,b,c) for(a=b;a<=c;++a)
#define _ std::
int a[100][100],t,n,i,j,x;main(){_ cin>>t;while(t--){_ cin>>n;f(i,1,n)f(j,1,i)_ cin>>a[i][j],a[i][j]=_ max(a[i-1][j],a[i-1][j-1])+a[i][j],x=_ max(x,a[i][j]);_ cout<<x<<_ endl;x=0;}}
PS- I am open to criticism, please post any improvements that you can suggest.
#include<iostream>
ReplyDelete#define for(a,b,c) for(int a=b;a<=c;a++)
using namespace std;long a[101][101],r;
main()
{cin>>r;
for(t,1,r)
{
long l,m=0;cin>>l;
for(i,1,l)for(j,1,i)
{
cin>>a[i][j];
(a[i][j]=max(a[i-1][j-1],a[i-1][j])+a[i][j])>m?m=a[i][j]:m;
}
cout<<m<<endl;
}
}
Above code Got AC with exactly 256 bytes.. Hurray
ReplyDeleteNice one vig :)
ReplyDeletefunny problem!
ReplyDelete#include
#define f(i,j) for(j=0;j<=i;++j)
#define _ std::
int T,n,i,j,M[100][100];main(){_ cin>>T;while(T--){_ cin>>n;for(i=0;i>M[i][j];for(i=n-2;i>=0;--i)f(i,j)M[i][j]+=_ max(M[i+1][j],M[i+1][j+1]);_ cout<<M[0][0]<<'\n';}}
#include
ReplyDeleteusing namespace std;
main(){int i,j,a[105][105]={0},t,n;cin>>t;while(t--){cin>>n;for(i=1;i<=n;i++)for(j=1;j<=i;j++){cin>>a[i][j];a[i][j]+=max(a[i-1][j],a[i-1][j-1]);}j=0;for(i=1;i<=n;i++)j=max(j,a[n][i]);cout<<j<<endl;}}
the above code is 243 bytes
#define f(a,c) for(a=1;a<=c;a++)
ReplyDelete#define s(v) scanf("%d",&v)
int max(a,b){return a>b?a:b;}
main(){int s,n,i,j,x,t[101][101];s(s);while(s--){x=0;s(n);f(i,n)f(j,i)s(t[i][j]),x=(t[i][j]+=max(t[i-1][j-1],t[i-1][j]))>x?t[i][j]:x;printf("%d\n",x);}}
#include
ReplyDelete#define R(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
int j,n,t,a[110][110],s;
main(){cin>>t;while(t--){cin>>n;s=0;R(i,1,n){R(j,1,i){cin>>a[i][j];a[i][j]+=max(a[i-1][j],a[i-1][j-1]);s=max(s,a[i][j]);}}cout<<s<<endl;}}
It takes 243 B. :)