362 - 18,000 Seconds Remaining
Moderator: Board moderators
-
- Experienced poster
- Posts: 103
- Joined: Tue Mar 25, 2008 11:00 pm
- Location: IUT-OIC, DHAKA, BANGLADESH
- Contact:
Re: 362 - IO tricky samples
abid_iut.
check ur pm inbox.
check ur pm inbox.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
It is more tough to become a good person.
I am trying both...............................
362 - time limit exceeded... pls help...
I really don't know how to optimize the code more than this... I got time limit exceeded..
.. please help...!!

Code: Select all
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token = new StringTokenizer(br.readLine());
int number = 0;
int size = Integer.parseInt(token.nextToken());
while (size > 0){
int sum = 0;
int sumTemp = 0;
int count = 0;
int value = 0;
int totalTime = 0;
int timeRemain = 0;
if (number != 0) System.out.println("");
System.out.println("Output for data set " + ++number + ", " + size + " bytes:");
while (sum != size){
if (count != 5){
token = new StringTokenizer(br.readLine());
value = Integer.parseInt(token.nextToken());
sum = sum + value;
sumTemp = sumTemp + value;
count++;
totalTime++;
}
else{
if (sumTemp != 0){
timeRemain = (int) Math.ceil((((size - sum)<<2) + (size - sum)) / (double)sumTemp);
System.out.println(" Time remaining: " + timeRemain + " seconds");
}
else{
System.out.println(" Time remaining: stalled");
}
count = 0;
sumTemp = 0;
}
}
if (count == 5){
System.out.println(" Time remaining: 0 seconds");
}
System.out.println("Total time: " + totalTime + " seconds");
token = new StringTokenizer(br.readLine());
size = Integer.parseInt(token.nextToken());
}
br.close();
}
catch(Exception e){
System.exit(0);
}
}
}
-
- New poster
- Posts: 1
- Joined: Fri May 15, 2009 6:09 am
362 WA
Any one could spot out the error?
[/code]
Code: Select all
[code]import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
long totalByte = in.nextLong();
ArrayList second = new ArrayList();
long eachByte =0;
long time = 0;
long round= 1;
long remainByte = 0;
long byteTransfer= 0;
double r=0.0;
int count = 0;
while (totalByte!=0)
{
remainByte = totalByte;
while (remainByte>0)
{
eachByte = in.nextLong();
byteTransfer +=eachByte;
remainByte -= eachByte; // decrease bytes
time++; // totall seconds
count++;
if (count==5)
{
count = 0;
if (byteTransfer!=0)
{
r = (remainByte/(byteTransfer/5.0));
second.add((long)Math.ceil(r));
}
else
{
second.add("d");
}
byteTransfer=0;
}
}
System.out.println("Output for data set "+round+", "+totalByte+" bytes:");
//long _5= time-5;
//if (_5>=0)
//{
if (second.size()!=0)
{
for (int i=0; i<second.size();i++)
{
if (second.get(i).equals("d"))
System.out.println(" Time remaining: stalled");
else
System.out.println(" Time remaining: "+second.get(i)+ " seconds");
}
}
//}
System.out.println("Total time: "+time+ " seconds");
System.out.println();
round++;
second.clear();
byteTransfer = 0;
count = 0;
r =0.0;
time =0;
totalByte = in.nextLong();
}
}
}
ACM NO : 362(18000 Seconds remaining)
Code: Select all
Acc At last

Re: 362 - IO tricky samples
Its a really interesting problem to me,it seems very easy at 1st look.But now i got 10 time WA on that and still i cannot understand where my problem is.
I give my code below,plz try to help me with giving correction or any type of tips for the code.
I give my code below,plz try to help me with giving correction or any type of tips for the code.
Code: Select all
Code Removed After Accepted.
Last edited by mustak on Mon Apr 26, 2010 11:02 pm, edited 1 time in total.
-
- New poster
- Posts: 2
- Joined: Tue Sep 29, 2009 5:11 am
Re: 362 - IO tricky samples
I got 15 time WA --'
i dont know where is my problem,
My code is below,plz heelpp me
i dont know where is my problem,
My code is below,plz heelpp me
Code: Select all
#include <stdio.h>
#include <math.h>
main()
{
long le=0,x=0;
scanf("%i",&le);
while(le!=0)
{
x++;
long sec=0,sec2=0,cont=0,cont2=0,otra,b;
double remainSeconds;
printf("Output for data set %d, %d bytes:\n",x,le);
while(le>cont){
scanf("%i",&otra);
cont=cont+otra;
cont2=cont2+otra;
sec++;
sec2++;
if (sec2==5)
{
int remainbyte=le-cont;
remainSeconds=remainbyte/(cont2/5.0);
if(cont2==0){
printf(" Time remaining: stalled\n");
}else{
printf(" Time remaining: %d seconds\n",long((ceil(remainSeconds))));
}
sec2=0;
cont2=0;
}
}
printf("Total time: %d seconds\n", sec);
scanf("%i", &le);
printf("\n");
}
}
-
- New poster
- Posts: 2
- Joined: Tue Sep 29, 2009 5:11 am
362 - (18000 Seconds remaining) - WA
Hey guys,
i dont understand,i got 15 time WA,
plz help me!!!
i dont understand,i got 15 time WA,
plz help me!!!
Code: Select all
#include <stdio.h>
#include <math.h>
main()
{
long le=0,x=0;
scanf("%i",&le);
while(le!=0)
{
x++;
long sec2=0,sec=0,cont=0,cont2=0,otra,b;
double remainSeconds;
printf("Output for data set %d, %d bytes:\n",x,le);
while(le>cont){
scanf("%i",&otra);
cont=cont+otra;
cont2=cont2+otra;
sec++;
sec2++;
if (sec2==5)
{
int remainbyte=le-cont;
remainSeconds=remainbyte/((float)cont2/5.0);
if(cont2==0){
printf(" Time remaining: stalled\n");
}else{
printf(" Time remaining: %d seconds\n",long((ceil(remainSeconds))));
}
sec2=0;
cont2=0;
}
}
printf("Total time: %d seconds\n", sec);
scanf("%i", &le);
printf("\n");
}
}
-
- New poster
- Posts: 1
- Joined: Tue Jul 20, 2010 6:57 pm
362 - WA
I have written this code for problem 362 but I am getting WA .. anyone suggestions??
Code: Select all
#include <iostream>
#include <string>
#include<sstream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#define length(a) (sizeof a / sizeof a[0])
using namespace std;
int main()
{
//freopen ("a.txt","r",stdin);
//freopen ("a.out","w",stdout);
int size,sum,secondsCounter,temp,setCounter=0;
while(true)
{
queue<int> numbers;
secondsCounter=0;
sum=0;
cin>>size;
if(size==0)
break;
setCounter++;
if(setCounter>1)
cout<<endl;
while(sum<size)
{
cin>>temp;
sum+=temp;
secondsCounter++;
numbers.push(temp);
}
cout<<"Output for data set "<<setCounter<<", "<<size<<" bytes:"<<endl;
if(numbers.size()<5)
cout<<"Total time: "<<secondsCounter<<" seconds"<<endl;
else
{
while(!numbers.empty())
{
if(numbers.size()<5)
break;
int s=0;int i=0;
for(i=1;i<=5;i++)
{
s+=numbers.front();
numbers.pop();
}
if(s==0)
cout<<" Time remaining: stalled"<<endl;
else
{
sum-=s;
double remainSecond;
remainSecond = sum/(s/5.0);
//double TR = ceil(sum/avg);
cout<<" Time remaining: "<<round(remainSecond)<<" seconds"<<endl;
}
}
cout<<"Total time: "<<secondsCounter<<" seconds"<<endl;
}
}
cout<<endl;
//system("pause");
return 0;
}
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 362 - IO tricky samples
HORRIBLE. DONT WASTE YOUR TIME SOLVING THIS,THERE ARE LOTS OF OTHER PROBLEMS.
after 6 wa i got ac with this:
after 6 wa i got ac with this:
Code: Select all
double remainSecond = (5*(double)rem)/(double)fsum;
printf(" Time remaining: %d seconds\n",int(ceil(remainSecond)));
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 362 - IO tricky samples
One of the worst problems I've seen here
I feel like kicking my monitor-.- Thanks a lot for the snippet @Shafaet_DU. Thanks to sijan too. Finally got Accepted. 



You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Re: 362 - IO tricky samples
As other people have observed, this problem looks simple but is quite tricky.
There are two things that you need to keep in mind:
(1)
However, as crazy at this sounds, this gives an AC
In my program, remainingBytes and transferedBytes are both variables of type double.
(2)
Remember to print a newline after each case - including the last one.
Good luck!
There are two things that you need to keep in mind:
(1)
As fR0D mentioned, this line gives a WAfR0D wrote: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.
Code: Select all
printf(" Time remaining: %.0f seconds\n",ceil(remainingBytes/(transferedBytes/5.0)));
Code: Select all
printf(" Time remaining: %.0f seconds\n",ceil(remainingBytes/(transferedBytes*0.2)));
(2)
Remember to print a newline after each case - including the last one.
Good luck!
Last edited by uDebug on Sat Mar 01, 2014 1:34 pm, edited 1 time in total.
Re: 362 - IO tricky samples
Hello!
I have tried almost everything I read in this forum, but every time I got Wrong Answer (but for the examples I got the rigth answers). I think there must be a problem with the output formatting. Could someone help me, because I can not get through this. Here is the code:
I have tried almost everything I read in this forum, but every time I got Wrong Answer (but for the examples I got the rigth answers). I think there must be a problem with the output formatting. Could someone help me, because I can not get through this. Here is the code:
Code: Select all
import java.io.*;
import java.util.*;
//ACM 362 18,000 Seconds Remaining
/*
* The first line telling the size of the file in bytes.
* The subsequent lines will be the number of bytes transmitted in each second
* The end of input will be indicated by a file size of 0 bytes
*
* The output for each data set should begin with a line with the number of the data set
* and the size of the file being transferred.
* Then, there should be update lines estimating how many seconds remain,
* issued once every 5 seconds during the transfer.
*/
class Main {
static void calculateSpeed(long bytes, long iteration) {
long input = 0, totalbytes = 0, rate = 0, tmp, remaining;
Scanner scnr = new Scanner(System.in);
System.out.println("Output for data set " + iteration + ", " + bytes
+ " bytes:");
while (true) {
tmp = scnr.nextLong();
// line number or sec
input++;
totalbytes += tmp;
rate += tmp;
if (input % 5 == 0) {
// print rate
if (rate == 0)
System.out.println(" Time remaining: stalled");
else {
remaining = rate / 5;
Double d = (5 * (double) (bytes - totalbytes) / rate);
d = Math.ceil(d);
remaining = d.longValue();
System.out.println(" Time remaining: " + remaining
+ " seconds");
}
rate = 0;
}
if (totalbytes >= bytes)
break;
}
System.out.println("Total time: " + input + " seconds");
}
public static void main(String[] args) throws NumberFormatException,
IOException {
Main myWork = new Main();
myWork.Begin();
}
void Begin() throws NumberFormatException, IOException {
long bytes, iteration = 0;
Scanner input = new Scanner(System.in);
while (true) {
bytes = input.nextLong();
// read until the 0 bytes sign
if (bytes == 0) {
input.close();
return;
}
// how many rates have been computed
iteration++;
// write new line after every case
if (iteration > 1)
System.out.println();
calculateSpeed(bytes, iteration);
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 362 - IO tricky samples
You're calling new Scanner(System.in) multiple times, try just doing that once.
Check input and AC output for thousands of problems on uDebug!
Re: 362 - IO tricky samples
Thank you brianfry713, it helped! And also I had to write a new line after EVERY case, even after the last one, or I got a wrong answer.
Re: 362 - IO tricky samples
Glad you figured it out.kukker wrote:And also I had to write a new line after EVERY case, even after the last one, or I got a wrong answer.
If only you had read what was written in the post above yours
P.S: I edited my original post to make this more clear by adding some more emphasis. Hopefully it helps out future problem-solvers.(2)
Remember to print a newline after each case - including the last one.