## 11677 - Alarm Clock

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

Moderator: Board moderators

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

### 11677 - Alarm Clock

Help me!
i am getting wrong answer for that problem.Dont know why?
Can any one give me some critical input?

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

### 11677 ways to improve timing

Hi,

Following is the code:

Code: Select all

``````  3 int main()
4 {
5         int pad = 24*60;
6         int h1;
7         int h2;
8         int m1;
9         int m2;
10
11         scanf("%d %d %d %d", &h1, &m1, &h2, &m2);
12         while (h1 != 0 || h2 != 0 || m1 != 0 || m2 != 0)
13         {
14                 //int current_time = h1*60+m1;
15                 //int alarm_time = h2*60+m2;
16
17                 //if (h2 < h1 || (h2 == h1 && m2 < m1))
18                 //{
19                 //      h2 += 24;
20                 //}
21
22                 //if (m2 < m1)
23                 //{
24                 //      m2 += 60;
25                 //      h2--;
26                 //}
27                 int d_m = m2 - m1;
28                 int d_h = h2 - h1;
29                 int d_t = d_h*60+d_m;
30                 if (d_t < 0)
31                 {
32                         d_t += pad;
33                 }
34                 printf("%d\n",d_t);
35                 scanf("%d %d %d %d", &h1, &m1, &h2, &m2);
36         }
37         return 0;
38 }
``````
The timing is coming out as 0.004. As you can see I just used 2 subtractions to calculated difference and 1 multiplication to convert into minutes. I guess this is the minimum number of operations required. And also I precomputed the pad (=24*60) to avoid recomputation. Then why is it showing 0.004 instead of 0.000? I can't imagine any further way to eliminate any operations.

yeasin_acm_solver
New poster
Posts: 11
Joined: Wed Jun 09, 2010 2:30 pm
Location: University Of Science & Technology Chittagong (USTC) Bangladesh

### Re: 11677: Alarm Clock

/***************************************************/
E-mail: gigabyte_yeasin@yahoo.com
University of Science & Technology Chittagong (USTC)
CSE- 11th Batch
/***************************************************/
Input:

1 1 1 1
0 1 1 0
1 1 2 2
2 2 1 1
3 15 3 10
3 15 2 15
1 5 3 5
23 59 0 34
21 33 21 10
0 0 0 0

Output:

0
59
61
1379
1435
1380
120
35
1417

naseef_07cuet
Learning poster
Posts: 62
Joined: Sat Nov 21, 2009 10:17 pm

### Re: 11677: Alarm Clock

try this:-
input:-
5 3 2 1
3 2 1 1
1 6 1 5
Output will be:-
1258
1319
1439

best of luck
If you have determination, you can do anything you want....

shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

### Re: 11677 ways to improve timing

Bro please remove ur code... It may b harmful for Other user's....

Everyone should Think differently...Thus we may make a Difference....
I'll keep holding on...Until the walls come tumbling down...And freedom is all around .....

naseef_07cuet
Learning poster
Posts: 62
Joined: Sat Nov 21, 2009 10:17 pm

### Re: 11677 ways to improve timing

you are absolutely right Shawon...
If you have determination, you can do anything you want....

ItaloSpedini
New poster
Posts: 9
Joined: Sat Sep 11, 2010 1:21 am
Location: Rio de Janeiro - Brasil

### Re: 11677: Alarm Clock

My code is ok for all the inputs above, and i'm getting wrong answer. I'm not using system("pause") in my code but it's not being accepted.
Computer Science - UERJ - Rio de Janeiro - Brasil.

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

### WA in Problem - 11677

I don't understand what is the wrong in my code. I can't fix the problem. Hope someone can give the accurate reason that's why I got WA.
Here is my code:

Code: Select all

``code removed after AC``
Last edited by shondhi on Fri Nov 02, 2012 10:45 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: WA in Problem - 11677

Try input 0 5 1 5
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

### Re: WA in Problem - 11677

thank you for your reply. Can you please tell me what will be the output for the input 0 5 1 5?
Is it 60?

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

### Re: WA in Problem - 11677

Can you provide me a few more sample input?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: WA in Problem - 11677

Yes the output for 0 5 1 5 should be 60. You can generate your own test cases at:
http://www.uvatoolkit.com/problemssolve.php
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

### Re: WA in Problem - 11677

Thanks, it is already got AC.

opsori
New poster
Posts: 1
Joined: Sun Sep 15, 2013 11:49 pm

### P-11677what's wrong with my code. i got submissionErr

#include<stdio.h>

int main()
{
long int i,h1,m1,h2,m2,H,M,time;
for(i=1;;i++)
{
scanf("%ld %ld %ld %ld",&h1,&m1,&h2,&m2);
if(h1==0)
{
h1=24;
}
if(h2==0)
{
h2=24;
}
if(h1<h2&&m1<=m2)
{
H=h2-h1;
M=m2-m1;
time=H*60+M;
printf("%ld\n",time);
}
if(h1<h2&&m2<m1)
{
H=(h2-(h1+1));
M=m2+60-m1;
time=H*60+M;
printf("%ld\n",time);
}
if(h2<=h1&&m2<=m1)
{
H=(h2+24)*60+m2;
M=h1*60+m1;
time=H-M;
printf("%ld\n",time);
}
if(h2<h1&&m1<m2)
{
H=h2+24-h1;
M=m2-m1;
time=H*60+M;
printf("%ld\n",time);
}
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: P-11677what's wrong with my code. i got submissionErr

Check input and AC output for thousands of problems on uDebug!