Page **1** of **2**

### 11677 - Alarm Clock

Posted: **Tue Nov 10, 2009 5:08 pm**

by **sms.islam**

Help me!

i am getting wrong answer for that problem.Dont know why?

Can any one give me some critical input?

### 11677 ways to improve timing

Posted: **Wed Feb 10, 2010 8:00 am**

by **amishera**

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.

### Re: 11677: Alarm Clock

Posted: **Sat Jun 19, 2010 12:00 pm**

by **yeasin_acm_solver**

/***************************************************/

Muhammad Yeasin Lincon

E-mail:

gigabyte_yeasin@yahoo.com
University of Science & Technology Chittagong (USTC)

CSE- 11th Batch

Bangladesh

/***************************************************/

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

### Re: 11677: Alarm Clock

Posted: **Thu Jul 01, 2010 10:00 pm**

by **naseef_07cuet**

try this:-

input:-

5 3 2 1

3 2 1 1

1 6 1 5

Output will be:-

1258

1319

1439

best of luck

### Re: 11677 ways to improve timing

Posted: **Thu Aug 12, 2010 10:28 am**

by **shaon_cse_cu08**

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

Everyone should Think differently...Thus we may make a Difference....

### Re: 11677 ways to improve timing

Posted: **Fri Aug 13, 2010 12:56 pm**

by **naseef_07cuet**

you are absolutely right Shawon...

### Re: 11677: Alarm Clock

Posted: **Sat Sep 11, 2010 1:28 am**

by **ItaloSpedini**

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.

### WA in Problem - 11677

Posted: **Wed Oct 10, 2012 8:01 pm**

by **shondhi**

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:

### Re: WA in Problem - 11677

Posted: **Fri Oct 12, 2012 11:49 pm**

by **brianfry713**

Try input 0 5 1 5

### Re: WA in Problem - 11677

Posted: **Sat Oct 13, 2012 2:51 pm**

by **shondhi**

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?

### Re: WA in Problem - 11677

Posted: **Sat Oct 13, 2012 4:25 pm**

by **shondhi**

Can you provide me a few more sample input?

### Re: WA in Problem - 11677

Posted: **Tue Oct 16, 2012 1:27 am**

by **brianfry713**

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

### Re: WA in Problem - 11677

Posted: **Tue Oct 16, 2012 10:35 am**

by **shondhi**

Thanks, it is already got AC.

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

Posted: **Mon Sep 16, 2013 10:57 pm**

by **opsori**

#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;

}

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

Posted: **Mon Sep 16, 2013 11:09 pm**

by **brianfry713**