## 10714 - Ants

Moderator: Board moderators

New poster
Posts: 4
Joined: Wed Aug 10, 2005 10:43 pm
Contact:

### 10714 - Ants

I solved this (but not got AC) problem like...
minimum time = max(mininum time to get out of the pol)
and
maximum time = max(maximum time to get out of the pol)

So, can anyone tell me what is wrong with me.
Hul Hul

Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong
I've seen someone who got WA because he forgot to initialize the min and max variable for each test case.

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

### Re: 10714 Ants

If still getting WAs, try to post your code here...

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

It Is A Easy & Sort Problem.But If U Want I Can Sent Some I/O For You

Solmon K.
New poster
Posts: 34
Joined: Sun Jun 04, 2006 4:57 am
Location: Busan, Korea

### ...

I think ur algo is not wrong..

OTL
frustrate

marif
New poster
Posts: 11
Joined: Sat Jun 24, 2006 11:42 am
Contact:

### wa on this problem

Pls help me. W.A. is boaring. I used simple searching algo...
minimum value
{
i=last item that is found (and matched) before the mid value.
j=first item that is found (and matched) after the mid value.
if(i>(total length-j))minimum=i;
else minimum=total length-j;
}

maximum value
{
i=the smallest item of the array.
j=the largest item of the array.
if((total length -i)>j)
maximum=total length-i;
else maximum=j;
}
what is the wrong with it. I have used few inputs on this board and it was ok. Pls help.

rahurprem
New poster
Posts: 10
Joined: Mon Mar 28, 2005 5:59 pm
Contact:

### 714: Ants --- Some critical I/O please

I'm getting WA in this problem. I'm sending my findMin() & findMax() code blocks. I hope until now that those two blocks are producing correct results. So help me in this matter.

Code: Select all

``````int findMin()
{
int i;
int min = L;
int mid = L/2;   /*This is the mid of pole*/

/**mid theke shobcheye kaser ant khojo**/
/**Let's find which ant is closest to the mid position****/

/*STEP 1: Search Left side upto mid**/
for(i=0; a[i]<mid; i++)
{
if(min> abs(a[i]-mid))
min = abs(a[i]-mid);
}
/*STEP 2: Search from Right side upto mid**/
for(i=N-1; a[i]>=mid; i--)
{
if(min>abs(a[i]-mid))
min = abs(a[i]-mid);
}
return mid-min;	/*This is the minimum distance, isn't it?*/
}
``````

Code: Select all

``````int findMax()
{
int i,j;
int max=-1;

/***
i=the smallest item of the array.
j=the largest item of the array.
if((total length -i)>j)
maximum=total length-i;
***/
i = a[0];
j = a[N-1];
if((L-i)>j)
max= L-i;
else
max= j;

return max;
}
``````
It'll be a great help if you provide me some i/o to prove this algo wrong.
Wishes,
R.P.
Programmer? No, no, i am a speedy typist.

unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

### 10714 - Ants W.A

I got W.A on this problem. Could someone plz give me the I/O.
Here is my code:

REMOVED AFTER AC!
Last edited by unaben on Tue Jul 25, 2006 11:29 pm, edited 1 time in total.

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

### Re: 10714 - Ants W.A

unaben wrote:I got W.A on this problem. Could someone plz give me the I/O.
What if hold==distance?
.......{
...........min = hold;
.......}....
.......else if(hold>distance and distance>min)
.......{
...........min = distance;
.......}...

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

### Re: 714: Ants --- Some critical I/O please

rahurprem wrote:I'm getting WA in this problem. I'm sending my findMin() & findMax() code blocks. I hope until now that those two blocks are producing correct results. So help me in this matter.
I think your findMin() doesn't work for odd Ls. Think about something like that:

Code: Select all

``````1
3 1
3
``````

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

### Re: 10714 - Ants W.A

and btw, if there is a thread on a particular problem, please, use that thread and do not create a new one.

unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm
Thanx Macko What a stupid mistake. I got AC now

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)
unaben wrote:Thanx Macko What a stupid mistake. I got AC now
After you got AC, please, remove the code from your first post, so there won't be too many spoilers here

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

### Why WA??

I have absolutely no idea why I'm getting WA.
Here's the code:

Code: Select all

``````#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<cctype>
#include<stack>
#include<map>
#include<set>
using namespace std;

int main()
{
int cases;
cin>>cases;
while(cases--)
{
int l,n;
scanf(" %d %d",&l,&n);
vector<int> v(n);
for(int i=0;i<n;i++)
{
scanf(" %d",&v[i]);
}
sort(v.begin(),v.end());
int ma=max(l-v[0],v.back());
int mi=ma;
for(int i=0;i<n-1;i++)
{
mi=min(mi,max(v[i],l-v[i+1]));
}
if(n==1)
mi=min(v[0],l-v[0]);
printf("%d %d\n",mi,ma);
}
return 0;
}
Could anyone provide me with I/0?``````

Grazyna
New poster
Posts: 16
Joined: Wed Apr 20, 2005 2:44 pm
Location: Thessaloniki,Greece
Can someone explain why the output for

Code: Select all

``````1
10 3
3 7 9
``````
is

Code: Select all

``````3 9
``````
and not

Code: Select all

``````3 8
``````