## 497 - Strategic Defense Initiative

Moderator: Board moderators

hankkuo
New poster
Posts: 1
Joined: Fri Nov 09, 2001 2:00 am
I always got a runtime error in 497.
The problem is a multiple input.
Although I read the help very carefully, I
still can't understand what I should do for
I got a confused for a long time.

I don't know what result in this reply.
or others??
Thx!!

<font size=-1>[ This Message was edited by: hankkuo on 2001-11-09 09:51 ]</font>

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore
I met with some problems while solving this problems too. Is there any trick in the test cases? Also, is the input file in this format?

2

1
2
3

2
3
1
-END-

Thanks.

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore
Try using C if you are using Pascal. Don't ask me why, but my pascal solution will NOT get accepted by the Judge. Anyway, for those who are still not clear about the input format, it's like this:

-START-
2

1
6
2
3
5

1
3
2
4
-END-

Output should be quite obvious, so I won't put it here.

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland
Hi
I have no idea why i have WA.
Could anyone help me???Program p497;

VAR
stos,tab,wynik,pop:array[1..8000] of integer;
wys,max,maxx,y,ilosc,x:longint;
begin
x:=0;
repeat
x:=x+1;
until eof;
ilosc:=x;
for x:=1 to ilosc do wynik[x]:=1;
for x:=1 to ilosc do pop[x]:=-1;
for x:=2 to ilosc do
begin
for y:=1 to x-1 do
begin
if tab[x]>=tab[y] then
begin
if wynik[y]+1>wynik[x] then
begin
wynik[x]:=wynik[y]+1;
pop[x]:=y;
end;
end;
end;
end;
max:=0;
maxx:=0;
for x:=1 to ilosc do
begin
if wynik[x]>max then
begin
max:=wynik[x];
maxx:=x;
end;
end;
Writeln('Max hits: ',max);
wys:=0;
repeat
wys:=wys+1;
stos[wys]:=tab[maxx];
maxx:=pop[maxx];
until maxx=-1;
for x:=wys downto 1 do Writeln(stos[x]);
end.

I have no idea????

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore
It's multiple input!

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland
Thanx.

I go P.E. (it is better than W.A)

Thanks a lot

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
I think my DP is correct. Can someone tell me why this code is WA? Thanks:o)

Code: Select all

``````#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

void main()
{
int i,j,k,N,Z,z,BL,BP;
char B[100];
vector<int> D,L,P,R;

scanf("%dnn",&Z);
for(z=0;z<Z;z++)
{
if(z>0)
printf("n");
D.clear();
while(gets(B)!=NULL)
{
if(sscanf(B,"%d",&N)!=1)
{
break;
}
else
{
D.push_back(N);
}
}
L=vector<int>(D.size(),-1);
P=L;

L[0]=1;
P[0]=-1;

for(i=1;i<D.size();i++)
{
BL=1;
BP=-1;
for(j=0;j<i;j++)
{
if(D[j]<D[i])
{
BL=L[j]+1;
BP=j;
}
}
L[i]=BL;
P[i]=BP;
}

j=max_element(L.begin(),L.end())-L.begin();
printf("Max hits: %dn",L[j]);

R.clear();

k=L[j];
while(k>0)
{
R.push_back(D[j]);
k--;
j=P[j];
}
reverse(R.begin(),R.end());
for(i=0;i<R.size();i++)
{
printf("%dn",R[i]);
}
}
}
``````

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland
Hi!

It is strange...
I have tested it but I couldn't find any mistake on my tests....

Maybe threre is something wrong with vectors...

Try to use normal table...

Good Luck

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
It gives me Wrong Answer not SIGSEV or some other wierd thing:P There must be some borderline case? I will try it with arrays and see.

chang
New poster
Posts: 16
Joined: Wed Jan 16, 2002 2:00 am
I suggest u to change a single line as follows:
while ( gets(B) && strlen(B) > 0 )
while ( gets(B) != NULL )

Hope u'll get it AC...

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
How would the strlen help? I break the loop if the scanf fails. So, shouldn't that take care of it?

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

### p497

I got WA for this problem, i don't know why ...
My source code should be OK, it works perfectly ...

pls help...
Last edited by sjn on Mon Feb 02, 2004 5:51 pm, edited 2 times in total.

Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

### so many source code posted

Did you read the problem carefully? Dont just post the code and ask why, why, why and why...
.. wrote:In these days, the board is full of source code....
Why do the people just hope others to debug for them?
-novice

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:
why are you reading and writing to files?

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:
to:Caesum

when i submit ,i'll delete the following:

assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);