481 - What Goes Up
Moderator: Board moderators
Re: 481 - What Goes UP (Run Time Error)
It's RTE with either.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 481 - What Goes UP (Run Time Error)
With C++11, you're getting TLE.
http://en.wikipedia.org/wiki/Longest_in ... ubsequence
Use binary search.
http://en.wikipedia.org/wiki/Longest_in ... ubsequence
Use binary search.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 50
- Joined: Tue Dec 17, 2013 11:01 pm
Re: 481 - What Goes UP (Run Time Error)
brianfry713
can you please give links to other problems that needs to be solved with binary search
can you please give links to other problems that needs to be solved with binary search
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 481 - What Goes UP (Run Time Error)
http://uhunt.felix-halim.net
Competitive Programming Exercises
Chapter 3. Problem Solving Paradigms
Divide and Conquer
Competitive Programming Exercises
Chapter 3. Problem Solving Paradigms
Divide and Conquer
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 481 - What Goes Up
I solved it in O(nlogk)
Last edited by Shahidul.CSE on Sat Mar 19, 2016 4:57 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 481 - What Goes UP (Run Time Error)
http://en.wikipedia.org/wiki/Longest_in ... ubsequence
Use binary search.
Use binary search.
Check input and AC output for thousands of problems on uDebug!
Re: 481 - What Goes Up
O(n^2) solution will get TLE
so must use O(nlogk) solution.
![:P](./images/smilies/icon_razz.gif)
481 run time error
someone help me with my code plz
i dont understand why it cause run time error
i dont understand why it cause run time error
Code: Select all
#include <stdio.h>
#include<string.h>
#include<math.h>
int main() {
// freopen("lis.inp","r",stdin);
int pred[1000],i,n,j,max=0,a[1000],s=0,l[1000],dmax,j0,x[1000],k,m,sa;
i=1;
while(scanf("%d",&sa)!=EOF)
{
a[i]=sa;
i++;
}
n=i-1;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
l[1]=1;
dmax=1;
pred[1]=-1;
pred[0]=-1;
for(i=2;i<=n;i++)
{
max=0;
j0=0;
for(j=i-1;j>=1;j--)
if(a[i]>a[j] && l[j]>max)
{
max=l[j];
j0=j;
}
l[i]=max+1;
pred[i]=j0;
if(l[i]>=dmax) {dmax=l[i];k=i;}
}
printf("%d\n",dmax);
printf("-\n");
m=0;
while(k!=-1)
{
m++;
x[m]=a[k];
k=pred[k];
if(k==0) break;
}
for(i=m;i>1;i--)
printf("%d\n",x[i]);
printf("%d\n",x[1]);
}
Last edited by brianfry713 on Tue Oct 27, 2015 3:11 am, edited 1 time in total.
Reason: Added code block
Reason: Added code block