## 362 - 18,000 Seconds Remaining

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

Moderator: Board moderators

Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

### Why wrong answer 362 18,000 seconds remaining

I could'nt find out the the logical or other types of error. I checked it for many input. For those it's 100% ok! But still it's getting WA..!
But Why?

If anybody can give the answer i will be very grateful to him.

Code: Select all

``````Removed after got AC
``````
Last edited by Mushfiqur Rahman on Sat Mar 03, 2007 3:07 pm, edited 1 time in total.

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am
well, I think, the problem is in the type casting.
u have casted "float" in one place in ur code...try with making it double.
and instead of dividing by 5 , divide by 5.0.
hope this will help u
u may visit http://online-judge.uva.es/board/viewtopic.php?t=5222
and i thing there are more threads for this problem here . U may post in those thread ,too.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

Mushfiqur Rahman
Learning poster
Posts: 56
Joined: Tue Jun 13, 2006 5:18 pm
Location: (CSE, SUST) Sylhet, Bangladesh
Contact:

### Thanks for Kallol

Dear Kallol,
Thanks to you for your great help. Now I got AC. When I changed my all variable into long int instead of doubel and then casting in double then it got AC. I sow your post after got AC. Then I checked my code with your tips but it got WA. So one should follow this suggestion that try to use all variable in long type and then cast it into double.

I am grateful to you.

N@\$!M
New poster
Posts: 10
Joined: Wed Jan 10, 2007 7:26 pm

### 362 P.E.

Here is My Code For Which I Have got P.E.

Code: Select all

``````#include<stdio.h>
#include<math.h>

int main(void)
{
double tb,takenTotal,takenPrev5,take;
long t,dataset = 1;
bool tag = false;

scanf("%lf",&tb);
while(tb!=0)
{
if(tag == false) tag = true;
else printf("\n");
...
...
...
...
...
dataset++;
}
return 0;
}
``````
.........CODE REMOVED
Last edited by N@\$!M on Mon Jun 25, 2007 5:54 pm, edited 1 time in total.
"I AM NOT SURE WHETHER I SHOULD BE CONFUSED OR NOT..."
TARIQ M NASIM
CSE 03/04 Batch, SUST, Sylhet- 3114.
==>Software Engineer, Structured Data Systems Limited,Dhaka.
Bangladesh.

e-Mail Address:
tariqmnasim@gmail.com

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
There should be a blank line after every case. But your code doesn't print a blank line after the last case.

Hope it helps.
Ami ekhono shopno dekhi...
HomePage

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

### 362 - WA please help me.

I have got it accepted but very much surprised!!!!!!!!!
Ii's a very much technical and fraction error.
so everyone be careful to handle fraction errors.
I type cast the double into long
Thanks all
Last edited by alamgir kabir on Wed Dec 24, 2008 9:38 pm, edited 1 time in total.

ligregni
New poster
Posts: 11
Joined: Thu Nov 29, 2007 12:41 am
Location: Queretaro, M
Contact:

### I have almost 40 submissions and still WA!!!

Hi, I'm desesperate, I need help!,

I have revewed all the output sentences, I tried all the cases I've found and they are OK!,

I also tried printing after each case (including last one) "\n\n", or printing after each case (including last) "\n", but printing after each case (except the last) "\n" (all of this is printing two \n after all cases exept the last, where I only print one) or printing "\n\n" after all cases except last one (who is "empty" after him),

I tried printing all of this combinations after scanning the # of bytes or before that (I need your help giving me the answer of the \n issue, it will help a lot),

I am almost sure the Math issue is correct (for avoid ceil(), I made the same calculus whith a double and an integer, if they are not the same, I print the integer (long actually) plus 1),

I remember you I've tried with all cases I've found and some extrem I thinked (for example, 10000 bytes, and in the first 5 seconds just one byte has been transferred, and after that one stalled, and then all the bytes less one tranfers, and calculus the time remaining),

I also checked all the ':' and that stuff,

I'm getting crazy with this problem,

I know it's OK, but UVa doesn't think the same, and I'm pretty sure it is by any little thing, but I don't know, what, so, here is my code:

Code: Select all

``````/* 18,000 Seconds Remaining */

#include <stdio.h>

int main ()
{
/* FILE *in = freopen ("c.in", "r", stdin); /**/

long b=0, B=0, c=0;

scanf("%i", &b);

while (b!=0)
{
c++;

/*		if (c!=1)
printf("\n");

*/
long sec=0, time[5];

printf("Output for data set %d, %d bytes:\n", c, b);

B=0;

while (B<b)
{
scanf("%i", &time[sec%5]);

B += time[sec%5];

sec++;

if (sec%5==0)
{
long suma=0, x=0;

double t=0.0;

while(x++<5)
suma += time[x-1];

t = suma/5.0;

double d=0;

if (t!=0)
{
x = (b-B)/t;

d = (b-B)/t;

if (x!=d)
x++;
}

printf("   Time remaining: ");

if (t==0)
printf("stalled\n");
else
printf("%i seconds\n", x);
}
}

printf("Total time: %i seconds\n", sec);

scanf("%i", &b);

if (b!=0)
printf("\n");

}

return 0;
}

``````
This version of my code is the one who prints \n after all cases and another \n after all cases except last one.

I get WA at 0.190 secs aprox, so I know it could be almost at the end.

aprox 5 of my WA was because I forgot to comment the FILE *in line, but I have trained myself to avoid that.

THANKS

Sergio Ligregni
C: multum in parvo

"a lot since quite few"

http://acmicpc-live-archive.uva.es/nuev ... user=12539

kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

### Re: 362 - WA many times but works for evry cases in forum...

AC,,,code deleted..
Its too pathetic that,,,when I used ceil(double vale) i got WA
when i used ceil(double value+1e-7)i got WA
when I used (int)(double value+.9999999)i got AC....but why?
so think everyone how much one should b careful calculating floating point numbers!
Last edited by kbr_iut on Fri Sep 19, 2008 10:55 pm, edited 1 time in total.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

mukit
New poster
Posts: 48
Joined: Wed Nov 21, 2007 10:09 am
Location: Dhaka , Bangladesh
Contact:

### Re: 362 why WA???

To Morning :
change the line :

Code: Select all

``aver /= 5;``
into

Code: Select all

``aver /= 5.0;``
And you should have print the output lines into proper format(spaces).
Like :

Code: Select all

``cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl; ``
would be

Code: Select all

``cout << "   Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;``
Hope this will work.

Mukit,
CSE,JU

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

### Re: 362 why WA???

To "Morning" you should use "return 0;" in "int main" function.
Else you can use void main.
try_try_try_try_&&&_try@try.com
This may be the address of success.

fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

### Re: 362 - IO tricky samples

can somebody please point out why am i getting WA?

Code: Select all

``````Got AC.
Changed the line
printf("   Time remaining: %.0f seconds\n",ceil(remainingBytes/((float)transferedBytes/5.0)));
to
printf("   Time remaining: %.0f seconds\n",ceil(remainingBytes/((double)transferedBytes*0.2)));
and GOT AC.
``````
i tried all test cases on forum and got expected answer still WA.
Last edited by fR0D on Sat Sep 20, 2008 8:49 am, edited 1 time in total.

wam3483
New poster
Posts: 1
Joined: Wed Sep 03, 2008 8:01 am

### 362 TLE... Please help me

OMFG ok, I've been working at this for 4 hours. I've joined this forum just because it seems like people round here know thier stuff (for the most part :].) I'm a java coder. I feel I'm pretty knowledgable, but Problem 362: 18,000 seconds left has just got me stumped.

Here's my code:

Code: Select all

``````import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int index = 0;
int totalBytes = scan.nextInt();
while (totalBytes > 0) {
System.out.println("Output for data set " + (++index) + ", "
+ totalBytes + " bytes:");

int bytesRead = 0, seconds = 0, count = 0;
double transWindow = 0;
//while more bytes to read
while (totalBytes > bytesRead) {
++seconds;
++count;
int temp = scan.nextInt();
transWindow += temp;
bytesRead += temp;
if (count == 5) {
if (transWindow > 0) {
System.out.println("   Time remaining: "
+ (int) Math.ceil((totalBytes - bytesRead)
/ (transWindow / 5.0)) + " seconds");
} else {
System.out.println("   Time remaining: stalled");
}
count =0;
transWindow=0;
}
}
System.out.println("Total time: " + seconds + " seconds\n");
totalBytes = scan.nextInt();
}
}
}
``````
Like I said, I get Time Limit Exceeded inside the 2nd "while" loop. I don't know why. I know it isn't infinte... I've tested a huge number of test cases against this code and I honestly can't find a thing wrong with it.

Please help me...

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

### Re: 362 TLE... Please help me

Use existing threads.
Ami ekhono shopno dekhi...
HomePage

kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

### Re: 362 - IO tricky samples

u can use that technic posted immediate before u.
suppose
double d contains ur result. u need to round (to ceil)
just use this
long=tem=(int)(d+.9999999);
print tem;

hope it will help.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

### Re: 362 why WA man!!!!!!!!

why WA it is giving every output right
here is the code:

Code: Select all

``````#include<stdio.h>
#include<math.h>

int main()
{
long size,time,count,sum,n=1,byte,line=0;
double aver,remainsecond;
while(scanf("%ld",&size)==1&& size){
if(line)printf("\n");
line=1;
printf("Output for data set %ld, %ld bytes:\n",n++,size);
sum=0;time=0;count=0;aver=0;
while(sum!=size){
scanf("%ld",&byte);
sum+=byte;
aver+=byte;
count++;
time++;
if(count==5){
count=0;
if(aver==0)printf("   Time remaining: stalled\n");
else {
remainsecond=(size-sum)/(aver/5.0);
printf("   Time remaining: %.0lf seconds\n",ceil(remainsecond));
}
aver=0;
}
}
printf("Total time: %ld seconds\n",time);
}
return 0;
}

``````
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/