# Chef and Meetings – Codechef Solution – February Challenge 2021 Division 3 A time is a string in the format “HH:MM AM” or “HH:MM PM” (without quotes), where HH and MM are always two-digit numbers. A day starts at 12:00 AM and ends at 11:59 PM. You may refer here for understanding the 12-hour clock format.
Chef has scheduled a meeting with his friends at a time P. He has N friends (numbered 1 through N); for each valid i, the i-th friend is available from a time Li to a time Ri (both inclusive). For each friend, can you help Chef find out if this friend will be able to attend the meeting? More formally, check if Li≤P≤Ri for each valid i.

## Input

• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains a single time P.
• The second line contains a single integer N.
• N lines follow. For each valid i, the i-th of these lines contains two space-separated times Li and Ri.

## Output

For each test case, print a single line containing one string with length N. For each valid i, the i-th character of this string should be ‘1’ if i-th friend will be able to attend the meeting or ‘0’ otherwise.

### Example Input

``````2
12:01 AM
4
12:00 AM 11:42 PM
12:01 AM 11:59 AM
12:30 AM 12:00 PM
11:59 AM 11:59 PM
04:12 PM
5
12:00 AM 11:59 PM
01:00 PM 04:12 PM
04:12 PM 04:12 PM
04:12 AM 04:12 AM
12:00 PM 11:59 PM``````

### Example Output

``````1100
11101``````

## Solution

``````include <bits/stdc++.h>
using namespace std;
define ll long long int
define ld long double
define str string
define F first
define S second
define all(x) begin(x), end(x)
define pb push_back
define mp make_pair
const int mxN=1e5;
int n, mh, mm, st1, st2, et1, et2;
char c;
string mt, mt1, mt2;
bool timeCount() {
bool a=false, b=false;
if(st1==et1 && st2==et2 && mh==st1 && mm==st2)return true;
if(mh>=st1) {
if(mh==st1 && mm>=st2)a=true;
else if(mh>st1)a=true;
if(et1>st1) {
if(mh<et1)b=true;
else if(mh==et1 && mm<=et2)b=true;
} else if(et1==st1) {
if(et2<st2)b=true;
else if(et2>st2 && mh==et1 && mm<=et2)b=true;
} else {
b=true;
}
} else {
if(mh<et1)a=true;
else if(mh==et1 && mm<=et2)a=true;
if(et1>st1) {
return false;
} else if(et1==st1) {
if(et2>st2)return false;
else if(et2<st2 && mh==et1 && mm<=et2)b=true;
} else {
if(mh<et1)b=true;
else if(mh==et1 && mm<=et2)b=true;
}
}
return a&&b;
}
void timeConvert() {
if(mt1=="AM") {
if(st1==12)st1=0;
} else {
if(st1!=12)st1+=12;
}
if(mt2=="AM") {
if(et1==12)et1=0;
} else {
if(et1!=12)et1+=12;
}
}
void solve() {
cin >> mh >> c >> mm >> mt >> n;
if(mt=="AM") {
if(mh==12)mh=0;
} else {
if(mh!=12)mh+=12;
}
for(int i=0;i<n;i++) {
cin >> st1 >> c >> st2 >> mt1 >> et1 >> c >> et2 >> mt2;
timeConvert();
if(timeCount())cout << '1';
else cout << '0';
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}``````

1,256 total views,  2 views today