← Back to topics
Topic

SuperClimber

M
Martin
I have been trying to solve this problem but when I send my solution it says TLE on every test sample. I think it works fast... If you know what is a problem or you know a better solution please help me.
This is my solution:

#include <cstdio>
using namespace std;
long long int p[100000][(25*2+1)];
int main ()
{
long long int n,k;
scanf ("%lld%lld",&n,&k);
int kraj=(k),poc=(k);
p[0][kraj]=1;
for (long long int i=0;i<n;i++)
{
for (int j=poc;j<=kraj;j++)
{
p[i+1][j]+=p[i][j]21555123;
if (j+1<=(k*2))p[i+1][j+1]+=p[i][j]21555123;
if (j-1>=0)p[i+1][j-1]+=p[i][j]21555123;
}
if (poc>0) poc--;
if (kraj<(k*2)) kraj++;
}
long long max=0;
for (long long i=0;i<=(k*2+1);i++)
{
max+=p[n][i];
}
printf ("%lld",max);
return 0;
}
D
Dgleich
First: you should mod with 321555123, second are are the test cases going with TLE really fast or slow?
If it's fast, too much memory used...
M
Martin
I'm sorry, I guess i did something wrong with copy/paste my code is:
#include <cstdio>
using namespace std;
long long int p[100000][(25*2+1)];
int main ()
{
long long int n,k;
scanf ("%lld%lld",&n,&k);
int kraj=(k),poc=(k);
p[0][kraj]=1;
for (long long int i=0;i<n;i++)
{
for (int j=poc;j<=kraj;j++)
{
p[i+1][j]+=p[i][j];
if (j+1<=(k*2))p[i+1][j+1]+=p[i][j];
if (j-1>=0)p[i+1][j-1]+=p[i][j];
}
if (poc>0) poc--;
if (kraj<(k*2)) kraj++;
}
long long max=0;
for (long long i=0;i<=(k*2+1);i++)
{
max+=p[n][i];
}
printf ("%lld",max);
return 0;
}

I used mod 321555123 (when i copy it here it doesn't show, it says "21555123" instead of "% 321555123"), but I still get TLE.
I think its fast, those 2 test samples work fast and i tried with some big numbers and It's still fast. I never thought it uses too much memory, because i thought it would say something like "memory limit exceded", but if that is the case then can you tell me if my idea is good for now?
p
picsel
100000*60 * long long is 48 MB