Page 1 of 7
Posted: Sun Mar 17, 2002 1:41 am
by Kamp
I've made this problem in every possible way and I have all the time WA

Any suggestions about the input???
Posted: Wed Mar 27, 2002 3:36 pm
by C8H10N4O2
Need to see code to be able to help.
Posted: Wed Mar 27, 2002 4:30 pm
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

Posted: Wed Mar 27, 2002 4:54 pm
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.
Posted: Wed Mar 27, 2002 5:45 pm
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

but maybe..
Thanx..
Posted: Wed Mar 27, 2002 5:52 pm
by cyfra
OH!
And the other question...
Is there only one test data in this task --> you have to read until End Of File ???
Posted: Thu Mar 28, 2002 2:58 am
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>
Posted: Thu Apr 04, 2002 2:00 pm
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
Posted: Thu Apr 04, 2002 6:10 pm
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.
Posted: Fri Apr 05, 2002 4:44 pm
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 
Posted: Fri Apr 05, 2002 5:55 pm
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.
acm 484
Posted: Sun Nov 17, 2002 8:01 am
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"
...
Posted: Mon Nov 18, 2002 4:53 am
by Fresh
The buffer size nop big enough?
-novice

Re: ...
Posted: Tue Nov 19, 2002 2:05 pm
by kelfin
Fresh wrote:The buffer size nop big enough?
-novice

thanks , but i get "Time Limit Exceeded". ><"
...
Posted: Wed Nov 20, 2002 6:03 am
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
