## 362 - 18,000 Seconds Remaining

Moderator: Board moderators

malf
New poster
Posts: 7
Joined: Tue Aug 17, 2004 5:43 pm

Ghust_omega
Experienced poster
Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela
Thanks malf but I try all that input and i got the same answer please help me someone that explain me why is wrong
[c]
#include <stdio.h>
#include <math.h>

int main(){
unsigned long tb=0,tt=0,bt=0,btt5=0,btt=0;
double tre=0,tr=0;
int set=1,count=0;

while(1){
scanf("%lu",&tb);
if(tb == 0)
break;
printf("Output for data set %d, %lu bytes:\n",set++,tb);
tt=btt=count=bt=btt5=0;
while(btt < tb){
scanf("%lu",&bt);
if(bt == 0){
count++;
}
btt += bt;
btt5 += bt;
tt++;
if(tt%5 == 0 && count != 5 && btt5 != 0){

tr = (double)btt5 / 5.0;
tre = (double)(tb - btt)/(tr);
printf(" Time remaining: %ld seconds\n",(long)ceil(tre));
btt5=count=0;
}
if(count == 5){
printf(" Time remaining: stalled\n");
btt5=count=0;
}
}
printf("Total time: %lu seconds\n\n",tt);

}
return 0;
}[/c]

malf
New poster
Posts: 7
Joined: Tue Aug 17, 2004 5:43 pm
Maybe is the precision of your "tb" variable...
Still looking wolf
New poster
Posts: 34
Joined: Sun Aug 22, 2004 4:20 am
Location: Poland
Can anybody check my code too (I have right answers for every input I find in all the posts in this forum):

[cpp]
#include <iostream>
#include <math.h>

using namespace std;

long long set,csuma,tsuma,tbytes,rbytes,i,secleft,k;
double bitrate;

void czytaj()
{

cout << "Output for data set " << set << ", " << tbytes << " bytes:" << endl;
for (i=0,tsuma=0,csuma=0,k=1;;k++)
{
cin >> rbytes;
tsuma+=rbytes;
csuma+=rbytes[i++];
if (i==5)
{
i=0;
if (csuma==0)
{
cout << " Time remaining: stalled" << endl;
continue;
}
bitrate=double(csuma/5.0);
csuma=0;
secleft=(long long)ceil(double(tbytes-tsuma)/(double)bitrate);
cout << " Time remaining: " << secleft << " seconds" << endl;
}
if (tsuma==tbytes) break;
}
cout << "Total time: " << k << " seconds" << endl << endl;
}

int main()
{
for (set=1;;set++)
{
cin >> tbytes;
if (tbytes==0) break;
czytaj();
}
return 0;
}
[/cpp]

Ghust_omega
Experienced poster
Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela
Hi can someone help me and give me some inputs where my code give the bad inputs please help me i with this prob please help Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

### 362 why WA???

it's really a simple problem,but why i keep getting WA???
[cpp]
#include <iostream>
using namespace std;
unsigned long ceiling(double x)
{
if(x - (unsigned long)(x) != 0) return (unsigned long)x + 1;
else return (unsigned long)(x);
}
int main()
{
unsigned long size,sum,count,t,n = 0,totalTime,flag = 1;
double aver;
while(cin >> size)
{
if(size == 0) break;
cout << "Output for data set "<< ++n << ", " << size << " bytes:" << endl;
totalTime = aver = count = sum = 0;
while(sum != size)
{
totalTime++;
count++;
cin >> t;
sum += t;
aver += t;
if(count == 5)
{
count = 0;
aver /= 5;
if(aver == 0)
{
cout << " Time remaining: stalled" << endl;
}
else
{
cout << " Time remaining: " << ceiling((size - sum) / aver) << " seconds" << endl;
}
aver = 0;
}
}
cout << "Total time: " << totalTime <<" seconds" << endl << endl;
}
}
[/cpp]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius

CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Hi, I got Acc after 7 WA and all credit goes towards u sjn. This problem made me sick....
Jalal : AIUB SPARKS

dootzky
New poster
Posts: 36
Joined: Tue Apr 12, 2005 12:20 am
Contact:

### ACCEPTED, finaly....

seriously, this is one of the problems that make you hate problem solving...

it's fairly simple, but it has a catch. like SJN said, you must do EXACTLY the following, or you won't get ACC.

remainSecond = remainBytes / (transferedBytes/5.0);
printf("%d seconds\n", ceil(remainSecond));

thx SJN for your insight. but i still don't get it.   Salman
New poster
Posts: 25
Joined: Thu Jun 26, 2003 9:45 am

### 362 is kill me

Hi I check all the test cases that I can found they match with the output but still getting WA. I am using long and double data structure is that is the cause?

Code: Select all

``````
/*
Name:   18000 seconds remaining
Number: 362
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 02/06/05 01:27

*/

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

int main()
{

long total,subtotal,input,sflag;
long flag=0,count=0,scount,secondtotal;
double rsecond,trate,bremain;

//   freopen("362.txt","r",stdin);

subtotal=0;
flag=0;
sflag=0;
count=1;
scount=0;
secondtotal=0;
bremain=0;

while(scanf("%ld",&input)!=EOF)
{

if(input==0 && flag==0)
{
break;
}

if(flag)
{
subtotal+=input;
secondtotal+=input;
scount++;
// printf("%d\n",scount);
}

if(scount!=0 && scount%5==0)
{

if(!secondtotal)
{
printf("   Time remaining: stalled\n");
}
else
{
trate =(double)secondtotal/5;
//printf("%d %d %lf %lf\n",scount,secondtotal,trate,bremain);
bremain=bremain-secondtotal;
//printf("%d %d %lf %lf\n",scount,secondtotal,trate,bremain);

rsecond=(bremain)/trate;
rsecond = ceil(rsecond);
//printf("%lf\n",rsecond);
printf("   Time remaining: %.0lf seconds\n",rsecond);
}
secondtotal=0;

}

if(!flag)
{

bremain=total=input;
if(sflag)
{
printf("\n");
}

printf("Output for data set %ld, %ld bytes:\n",count,total);
flag=1;
}

if(subtotal==total)
{
subtotal=0;
secondtotal=0;
bremain=0;
printf("Total time: %ld seconds\n",scount);
sflag=1;
flag=0;
scount=0;
count++;
}

}

return 0;
}

``````

willima
New poster
Posts: 13
Joined: Wed Dec 07, 2005 1:19 pm
Location: Brazil

### I can't understand!

I'm trying to solve 362 problem and I made more than 10 submissions and got very WA and 2 TLE. My program works for all the test cases you put in this board, but the judge still don't accept!

I think I'll leave this...

I do not know what's wrong. Does anybody know if I must use a struct for big integer numbers? Or using double, like the last post, is enogh.

Thanks!

--I'm getting crazy!

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Contact:
32 bits long should be enough! I did ceiling() though during division.

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:
Yeah I also got AC after doing the following:
float remainSecond = remainBytes / (transferedBytes/5.0);

float transferrate = (transferedBytes/5.0)
float remainSecond = remainBytes / transferrate;

Other than that, you can just use int and float for all your variables. No tricky input, though I wonder what it uses so much memory for. One additional security measure I took is (int)(ceil(remaining)+0.2) which I don't believe is really needed though based on the thread.

johnplayers
New poster
Posts: 5
Joined: Mon Apr 03, 2006 12:52 pm

### Thanks

I also got AC after what sjn told us to do. I was frustrated at not having been able to submit it for 3 days.

gvs
New poster
Posts: 6
Joined: Sun Jun 19, 2005 7:39 pm

### i'm relieved...

Man....
such problems are crap....
though I didn't divide by 5.0....
and then remaintime=ceil(remainbytes/rate);
then used %.0lf to printf the answer....

but if i used rate=transferredbytes/5.0;
then that ceil problem cropped up.... giving me WA.

another thing is that using '\t' for the 'Time remaining' message, gave me PE, whereas, using 'bbbTime remaining:'' (b=blank) gave me AC....
strange.....
does \t signify different lengths in different platforms ???
maKe wHat yoU waNt...... you'll succeed

asmaamagdi
New poster
Posts: 27
Joined: Tue Dec 20, 2005 9:14 am
Location: Egypt
Hi All,
I was getting WA for this problem, too till I edited something in the calculation of the remaining time.

Code: Select all

``````rate=size/5.0;
rem=remsize/rate;
``````
Then using ceil (rem) to display the remaining time.

U should write:

Code: Select all

``````rem=remsize/(size/5.0);
``````
Then use ceil (rem);

I wrote the second and got PE.
I hope this helps.

By the way, there is a discussion about this here. I knew about this from there 