10755 - Garbage Heap

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

vhua_no_name
New poster
Posts: 8
Joined: Sat Dec 21, 2013 8:48 pm

Re: 10755 - Garbage Heap

Post by vhua_no_name » Fri Feb 21, 2014 1:20 pm

i am getting WA ans for this problem. But it gives the same output as UVA toolkit for random test cases.
Don't know whats wrong with my code.
please some one take a look at my code (specially @brianfry713 :) ).

thanks in advance

Code: Select all

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long int t[22][22][22];
long long int w[22][22];
long long int p[22];

int main()
{
    int x,y,z,i,j,k,cases,a,b,c,i1,i2,j1,j2,caseno=1;
    int d,z1,z2;
    long long int v,maxi;

    cin>>cases;

    while(cases--)
    {
        cin>>x>>y>>z;
        a=1;b=1;c=1;

        while(a<=x)
        {
            scanf("%d",&k);
            t[c][a][b]=k;
            if(c==z)
            {
                c=1;
                if(b==y)
                {
                    b=1;
                    a++;
                }
                else
                    b++;
            }
            else
                c++;

        }
        /*cout<<"matrix:"<<endl;
        for(i=1;i<=z;i++)
        {
            for(j=1;j<=x;j++)
            {
                for(k=1;k<=y;k++)
                    cout<<t[i][j][k]<<" ";
                cout<<endl;
            }
            cout<<endl<<endl;
        }*/
        maxi=-2147483648LL;

        for(i1=1;i1<=x;i1++)
        {
            memset(w,0,sizeof w);
            for(i2=i1;i2<=x;i2++)
            {
                for(c=1;c<=z;c++){
                    for(j=1;j<=y;j++)
                        w[c][j]+=t[c][i2][j];
                }
                for(j1=1;j1<=y;j1++)
                {
                    memset(p,0,sizeof p);
                    for(j2=j1;j2<=y;j2++)
                    {
                        for(d=1;d<=z;d++){
                            p[d]+=w[d][j2];
                        }
                        for(z1=1;z1<=z;z1++)
                        {
                            v=0;
                            for(z2=z1;z2<=z;z2++)
                            {
                                v+=p[z2];
                                if(v>=maxi)
                                    maxi=v;
                            }
                        }

                    }
                }
            }
        }

        cout<<maxi<<endl;
        if(cases)
            cout<<endl;

    }
    return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10755 - Garbage Heap

Post by brianfry713 » Fri Feb 21, 2014 9:59 pm

Try input:

Code: Select all

1

1 1 1
2147483648
Check input and AC output for thousands of problems on uDebug!

vhua_no_name
New poster
Posts: 8
Joined: Sat Dec 21, 2013 8:48 pm

Re: 10755 - Garbage Heap

Post by vhua_no_name » Sun Feb 23, 2014 4:02 pm

thanks brianfry713 for your help. :wink:
i have found my mistake.

moxlotus
New poster
Posts: 31
Joined: Sat Sep 17, 2011 6:47 am

Re: 10755 - Garbage Heap

Post by moxlotus » Fri Aug 15, 2014 12:31 pm

Can someone explain this question to me? I do not comprehend the sample input/output :-?

Sample Input:
1

2 2 2
-1 2 0 -3 -2 -1 1 5

Sample Output:
6

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10755 - Garbage Heap

Post by brianfry713 » Sat Aug 16, 2014 12:41 am

It is hard to explain it better than the problem statement. You have to think in 3 dimensions. The original cube has a total value of 1.
By cutting it down to:
1 1 2
1 5

It has a total value of 6.
Check input and AC output for thousands of problems on uDebug!

moxlotus
New poster
Posts: 31
Joined: Sat Sep 17, 2011 6:47 am

Re: 10755 - Garbage Heap

Post by moxlotus » Sun Aug 17, 2014 10:38 am

Is this a 3D RSQ?

Post Reply

Return to “Volume 107 (10700-10799)”