Problem Statement: 1999A — A+B Again?
Since $$$n$$$ is a two-digit number, you can access each digit by simple arithmetic operations.
To find the sum of digits of a two-digit number $$$n$$$, divide $$$n$$$ by 10 to get the first digit and take $$$n$$$ modulo 10 to get the second digit. Adding these gives the desired result.
Time Complexity: $$$O(1)$$$ per test case Space Complexity: $$$O(1)$$$
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n / 10) + (n % 10) << endl;
return 0;
}
Problem Statement: B — Card Game
For each pair of cards, consider all possible matchups and count how many games Suneet can win by winning more rounds.
Each player has two cards, and the game consists of two rounds. For each matchup of cards, there are four possible ways for the players to reveal their cards. We simulate each of these cases and count how many result in Suneet winning more rounds than Slavic.
Time Complexity: $$$O(1)$$$ per test case
Space Complexity: $$$O(1)$$$
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
int count = 0;
int a[2] = {a1, a2}, b[2] = {b1, b2};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int suneet = 0, slavic = 0;
if (a[i] > b[j]) suneet++;
else if (a[i] < b[j]) slavic++;
if (a[1 - i] > b[1 - j]) suneet++;
else if (a[1 - i] < b[1 - j]) slavic++;
if (suneet > slavic) count++;
}
}
cout << count << endl;
}
return 0;
}
Problem Statement: C — Showering
Check each gap between tasks, as well as the beginning and end of the day, to see if there’s enough free time for Alex to shower.
Given Alex's tasks, represented as non-overlapping time intervals, we need to find a continuous free interval of at least $$$s$$$ minutes.
- Sort and scan the intervals:
- Check the time from the start of the day to the beginning of the first task.
- Check the gaps between tasks.
- Check from the end of the last task to the end of the day.
- If any of these free intervals is at least $$$s$$$ minutes, Alex can shower.
Time Complexity: $$$O(n)$$$ per test case
Space Complexity: $$$O(n)$$$ per test case
#include <bits/stdc++.h>
using namespace std;
int main () {
int t;
cin >> t;
while (t--) {
int n, time, total, temp;
cin >> n >> time >> total;
temp = n;
vector<pair<int, int>> v;
while (temp--) {
int x, y;
cin >> x >> y;
v.push_back({x, y});
}
int mx = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
mx = max(mx, v[i].first);
} else {
mx = max(mx, v[i].first - v[i - 1].second);
}
}
if (total - v[n - 1].second >= time) {
mx = time;
}
cout << ((mx >= time) ? "YES" : "NO") << endl;
}
return 0;
}