484 - The Department of Redundancy Department

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

Moderator: Board moderators

Post Reply
Kamp
New poster
Posts: 18
Joined: Tue Mar 05, 2002 2:00 am
Location: Poland (3-city)
Contact:

Post by Kamp »

I've made this problem in every possible way and I have all the time WA :sad: Any suggestions about the input???
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

Need to see code to be able to help.
cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra »

Hi!

I havee the same problem....
This program is quite simple...


Program p484;
CONST
ma =100000;

VAR
tab:array[1..ma] of longint;
ile:array[1..ma] of longint;
q3,q1,x,n,pop,w,un:longint;

Function znajdz(zm1:longint):longint;
VAR
wyn,z1:longint;
begin
wyn:=0;
for z1:=1 to un do if tab[z1]=zm1 then wyn:=z1;
znajdz:=wyn;
end;

begin

read(n);
un:=1;
tab[un]:=n;
ile[un]:=1;

repeat
if eoln then readln;

read(n);

w:=znajdz(n);
if w<>0 then ile[w]:=ile[w]+1 else
begin
un:=un+1;
tab[un]:=n;
ile[un]:=1;


end;


until eof;

for x:=1 to un do
begin
Writeln(tab[x],' ',ile[x]);
end;

end.


I hope you will find my mistake ...
This program passed every test I made :sad:
junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang »

I'm not sure, but when I tried to declare a large array, I got WA. But when I used pointers I got AC. So I think something goes wrong when your array is too large.

Bottom line, try using pointers.
cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra »

Hi!

I have often used large arrays and there were no problems with them....

But I will try to do this program with pointers...

(I don't think that this is the mistake :smile:
but maybe..

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

Post by cyfra »

OH!

And the other question...

Is there only one test data in this task --> you have to read until End Of File ???
Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann »

One general advice: Use speaking variable names. You probably do that already, but I don't know the language you use. So they don't speak to me.

Arrays are not the problem. You (almost?) always have 32 MB you can use, so you're not even close to exceeding it. Of course I don't know anything about Pascal, maybe it behaves strangely with large arrays. In C/C++/Java I never had a problem.

And yes, it's one big sequence, exactly as stated in the input definition.

<font size=-1>[ This Message was edited by: Stefan Pochmann on 2002-03-28 02:00 ]</font>
Kamp
New poster
Posts: 18
Joined: Tue Mar 05, 2002 2:00 am
Location: Poland (3-city)
Contact:

Post by Kamp »

Isn't something wrong with this input ???
3 1 2 2 1 3 5 3 3 2

3 4
1 2
2 3
5 1

I thing anwser should be:

3 4
1 2
2 2
5 1
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

No, the input is correct (there are 3 "2" in the sequence.
I used an integer array with 1000000 elements, sorted it with an index array and stored the number of times of appearance in another array at position k, where k is the first appearence of this number in the sequence. Perhaps this helps you.
Kamp
New poster
Posts: 18
Joined: Tue Mar 05, 2002 2:00 am
Location: Poland (3-city)
Contact:

Post by Kamp »

I've made something like this:

var
liczba:array[-100000..100000] of integer;
q1,q2,q3,i,x:longint;
tab:array[0..1000000] of longint;



begin
repeat
read(x);
if liczba[x]=0 then
begin
tab[0]:=tab[0]+1;
tab[tab[0]]:=x;
end;
liczba[x]:=liczba[x]+1;
until eoln;
for i:=1 to tab[0] do
begin
writeln(tab,' ',liczba[tab]);
end;
end.

But I still have WA :sad:
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

Read this line:
The input file will contain a sequence of integers (positive, negative, and/or zero).
That means the values are between -2^31 and 2^31-1. Therefore your program is not correct. I have described you my method. Try to implement it this way, or use an equivalent to map in C++ to store the values together with the number of apperances in the sequence.
kelfin
New poster
Posts: 4
Joined: Wed Nov 13, 2002 1:50 pm
Location: Taiwan

acm 484

Post by kelfin »

why I get "Wrong Answer" ?

Code: Select all

#include<stdio.h>
#include <string.h>
#include <stdlib.h>
 char y[1000000],*p;
 long ane[100000],i,j,k,ans;
 long temp[100000];
main()
{
 while(gets(y))
 {
  for(i=0;i<100000;i++)
  {temp[i]=0;ane[i]=0;}
  i=0;  ans=0;
  p=strtok(y," ");
  while(p!=NULL)
  {
   ane[i]=atoi(p);
   p=strtok(NULL," \n");
   i++;
  }
  for(j=0;j<i;j++){
   if(temp[j]==1)
     continue;
   for(k=j;k<i;k++){
    if(ane[j]==ane[k])
    {
     ans++;
     temp[k]=1;
    }
   }
   printf("%ld %ld\n",ane[j],ans);
   ans=0;
  }
 }
}
I change "char" to "int" but,"Wrong Answer"
Last edited by kelfin on Thu Nov 21, 2002 12:04 pm, edited 1 time in total.
Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

...

Post by Fresh »

The buffer size nop big enough?

-novice :-?
kelfin
New poster
Posts: 4
Joined: Wed Nov 13, 2002 1:50 pm
Location: Taiwan

Re: ...

Post by kelfin »

Fresh wrote:The buffer size nop big enough?

-novice :-?
thanks , but i get "Time Limit Exceeded". ><"
Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

...

Post by Fresh »

Change 'char' to 'int' and split the input as below,

[cpp]
while(gets(y))
{
int inp;
char *p = strtok(y);
while (p != NULL)
{ inp = atoi(p);
p = strtok(NULL," \n");
.....
.....
}
.....
.....
}
[/cpp]

-novice :wink:
Post Reply

Return to “Volume 4 (400-499)”