Page 5 of 6
Re: 10191 - Longest Nap
Posted: Wed Aug 15, 2012 7:09 pm
by invadrFlip
Thank you plamplam! Your test input saved me. I'm using java and was having difficulty printing the minutes in the hh:mm format when napStart % 60 was less than 10.
My code would print 14: 1 instead of 14:01. Apparently, my initial solution made it worse. Your test input found this problem while all before would not. Thanks.
Any ideas on how to format these strings in the future using java?
Re: 10191 Wrong Answer-but it always outputs correctly.
Posted: Thu Nov 01, 2012 6:50 pm
by Caren
Can anybody tell why this code gives
WA?? I am posting after applying many test cases. I have no idea now . Please help
Code: Select all
Removed After AC. Thanks to brianfry713. For others it may be helpful that there are overlapping schedules like below. Considered those and got AC
input:
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
12:00 12:05 Boring lectures...
15:30 17:45 Reading
output:
Day #1: the longest nap starts at 13:00 and will last for 2 hours and 30 minutes.
Re: 10191 Wrong Answer-but it always outputs correctly.
Posted: Fri Nov 02, 2012 12:03 am
by brianfry713
Input:
Code: Select all
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
12:00 12:05 Boring lectures...
15:30 17:45 Reading
AC output:
Code: Select all
Day #1: the longest nap starts at 13:00 and will last for 2 hours and 30 minutes.
Re: 10191 Wrong Answer-but it always outputs correctly.
Posted: Wed Jul 31, 2013 2:10 pm
by shuvokr
10191
Posted: Thu Aug 14, 2014 12:48 pm
by mamun30cse
why wrong ans?? help please.
#include<cstdio>
#include<stdio.h>
#include<cstring>
#include<string>
#include<cmath>
#include <sstream>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include <queue>
#include <vector>
#include<algorithm>
#include <iomanip>
#include <clocale>
#include <limits.h>
#include <bitset>
#include <utility>
#define Pi acos(-1.0)
using namespace std;
int main()
{
int n,day=0;
while(cin>>n)
{
int a[n+1][4],Max=0,a1,b1;
string line;
//input section
for(int i=0;i<n;i++)
{
scanf("%d:%d %d:%d",&a[0],&a[1],&a[2],&a[3]);
getline(cin,line);
}
a[n][0]=18;a[n][1]=0;a[n][2]=0;a[n][3]=0;
//processing
for(int i=1;i<n+1;i++)
{
int temp2 = (a[0] * 60) + a[1];
int temp1 = (a[i-1][2] * 60) + a[i-1][3];
int temp = temp2 - temp1;
if (temp> Max)
{
Max = temp;
a1=a[i-1][2];
b1=a[i-1][3];
}
}
int h,m;
if(Max>=60)
{
h=Max/60;
m=Max%60;
}
cout<<"Day #"<<cnt++<<": the longest nap starts at "<<a1<<":";
if(b1==0) cout<<"00";
else cout<<b1;
cout<<" and will last for ";
if(Max<60) cout<<Max<<" minutes.";
else cout<<h<<" hours and "<<m<<" minutes.";
cout<<endl;
}
return 0;
}
Re: 10191
Posted: Thu Aug 14, 2014 4:10 pm
by lighted
Your code gets Compile Error. Also your code doesn't match sample I/O.
I think you misunderstood the problem. You must calculate maximum free time, not maximum busy time.
Re: 10191
Posted: Thu Aug 14, 2014 9:29 pm
by mamun30cse
no, my code calculate maximum free time. Please check and help. Thanks.
Re: 10191
Posted: Thu Aug 14, 2014 10:22 pm
by brianfry713
Post your updated code that doesn't have a compile error.
Code: Select all
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:59:16: error: ‘cnt’ was not declared in this scope
cout<<"Day #"<<cnt++<<": the longest nap starts at "<<a1<<":";
^
prog.cpp:26:7: warning: unused variable ‘day’ [-Wunused-variable]
int n,day=0;
^
Re: 10191
Posted: Fri Aug 15, 2014 4:46 am
by lighted
I checked your code. You are calculating maximum free time.
You can search threads about your problem for input/output tests and information that may help. Just write problem number in search box.
http://acm.uva.es/board/search.php?keyw ... b1266e752b
I can give you some input from existing thread about 10191 on which your program fails.
amr saqr wrote:mhayter1 wrote:Can someone please help me. This problem is supposed to be easy, but I'm having a very tough time with it. My output seem right. Can someone point out the error in my code or give my inputs to break it. Thank you!
try this input
1
10:01 10:06
my output:
Code: Select all
Day #1: the longest nap starts at 10:06 and will last for 7 hours and 54 minutes.
your output:
Code: Select all
Day #1: the longest nap starts at 10:6 and will last for 7 hours and 54 minutes.
hope i helped u
brianfry713 wrote:Input:
Code: Select all
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
12:00 12:05 Boring lectures...
15:30 17:45 Reading
AC output:
Code: Select all
Day #1: the longest nap starts at 13:00 and will last for 2 hours and 30 minutes.
Re: 10191 - Longest Nap
Posted: Tue Oct 07, 2014 6:43 am
by fresher96
thanks a lot guys for the critical inputs
who would ever guess that this bastard is a multitask :3

Re: 10191 - Longest Nap
Posted: Sat Nov 01, 2014 6:55 pm
by MPC1984
Hi everybody!
I got WA for this problem, but I don't know why, all input cases in this thread are ok.
Here is my code:
Thanks in advance.

Re: 10191 - Longest Nap
Posted: Mon Nov 03, 2014 8:43 am
by lighted
Your code doesn't match 4th case of sample I/O.
http://ideone.com/QC4bnE
Re: 10191 - Longest Nap
Posted: Mon Nov 03, 2014 10:42 am
by MPC1984
Hi lighted!
My code it's OK for the input you said.
Look at
http://ideone.com/lTlMfH.
Re: 10191 - Longest Nap
Posted: Mon Nov 03, 2014 1:05 pm
by lighted
Try input
Code: Select all
102
14:10 17:30 Lectures101
12:00 12:01 Lectures1
12:01 12:02 Lectures2
12:02 12:03 Lectures3
12:03 12:04 Lectures4
12:04 12:05 Lectures5
12:05 12:06 Lectures6
12:06 12:07 Lectures7
12:07 12:08 Lectures8
12:08 12:09 Lectures9
12:09 12:10 Lectures10
12:10 12:11 Lectures11
12:11 12:12 Lectures12
12:12 12:13 Lectures13
12:13 12:14 Lectures14
12:14 12:15 Lectures15
12:15 12:16 Lectures16
12:16 12:17 Lectures17
12:17 12:18 Lectures18
12:18 12:19 Lectures19
12:19 12:20 Lectures20
12:20 12:21 Lectures21
12:21 12:22 Lectures22
12:22 12:23 Lectures23
12:23 12:24 Lectures24
12:24 12:25 Lectures25
12:25 12:26 Lectures26
12:26 12:27 Lectures27
12:27 12:28 Lectures28
12:28 12:29 Lectures29
12:29 12:30 Lectures30
12:30 12:31 Lectures31
12:31 12:32 Lectures32
12:32 12:33 Lectures33
12:33 12:34 Lectures34
12:34 12:35 Lectures35
12:35 12:36 Lectures36
12:36 12:37 Lectures37
12:37 12:38 Lectures38
12:38 12:39 Lectures39
12:39 12:40 Lectures40
12:40 12:41 Lectures41
12:41 12:42 Lectures42
12:42 12:43 Lectures43
12:43 12:44 Lectures44
12:44 12:45 Lectures45
12:45 12:46 Lectures46
12:46 12:47 Lectures47
12:47 12:48 Lectures48
12:48 12:49 Lectures49
12:49 12:50 Lectures50
12:50 12:51 Lectures51
12:51 12:52 Lectures52
12:52 12:53 Lectures53
12:53 12:54 Lectures54
12:54 12:55 Lectures55
12:55 12:56 Lectures56
12:56 12:57 Lectures57
12:57 12:58 Lectures58
12:58 12:59 Lectures59
12:59 13:00 Lectures60
13:00 13:01 Lectures61
13:01 13:02 Lectures62
13:02 13:03 Lectures63
13:03 13:04 Lectures64
13:04 13:05 Lectures65
13:05 13:06 Lectures66
13:06 13:07 Lectures67
13:07 13:08 Lectures68
13:08 13:09 Lectures69
13:09 13:10 Lectures70
13:10 13:11 Lectures71
13:11 13:12 Lectures72
13:12 13:13 Lectures73
13:13 13:14 Lectures74
13:14 13:15 Lectures75
13:15 13:16 Lectures76
13:16 13:17 Lectures77
13:17 13:18 Lectures78
13:18 13:19 Lectures79
13:19 13:20 Lectures80
13:20 13:21 Lectures81
13:21 13:22 Lectures82
13:22 13:23 Lectures83
13:23 13:24 Lectures84
13:24 13:25 Lectures85
13:25 13:26 Lectures86
13:26 13:27 Lectures87
13:27 13:28 Lectures88
13:28 13:29 Lectures89
13:29 13:30 Lectures90
13:30 13:31 Lectures91
13:31 13:32 Lectures92
13:32 13:33 Lectures93
13:33 13:34 Lectures94
13:34 13:35 Lectures95
13:35 13:36 Lectures96
13:36 13:37 Lectures97
13:37 13:38 Lectures98
13:38 13:39 Lectures99
13:39 13:40 Lectures100
10:29 11:30 Lectures102
Acc Output
Code: Select all
Day #1: the longest nap starts at 11:30 and will last for 30 minutes.
Re: 10191 - Longest Nap
Posted: Mon Nov 03, 2014 1:09 pm
by MPC1984
My code passed that input too (I'm executting the program from NetBeans framework), and I don't know why in
http://ideone.com/QC4bnE you get output different from mine.
Thank you for your help lighted!, but I've changed the algorithm and I've got AC. I think it's a problem of rounding numbers, if not I don't know where's the problem.
