Result: Accepted
Time: 5ms
Memory: 1092kB
#include<stdio.h>
#include<string.h>
int main() {
int t;
int t1,t2,ans;
int a,ta,b,tb,tr,tr2,x,y;
scanf("%d",&t);
while(t--) {
ans=0;
scanf("%d%d%d%d",&a,&ta,&b,&tb);
scanf("%d:%d",&t1,&t2);
// if(t1>=5&&((t1-5)*60+t2)%b==0) ++ans;
/*if(t1<5) {
ta=ta-(5-t1)*60+t2;
if(ta%b==0) printf("%d\n",ta/b);
else printf("%d\n",ta/b+1);
} else {*/
//if((23-t1)*60+59-t2<ta) ta=(23-t1)*60+59-t2+1;
//if((t1-5)*60+t2<tb) tb=(t1-5)*60+t2-1;
int f=t1*60+t2;
for(int i=300; i<1440; i+=b) {
if(i>f-tb&&i<f+ta) ++ans;
}
printf("%d\n",ans);
// }
/*ans+=ta/b;
ans+=tb/b;
if(tb%b==0&&y==tb) ans--;
if(ta%b==0&&x==ta) ans--;
printf("%d\n",ans);*/
}
}