Now that TCS Codevita is over I can finally get this off my chest. I cannot see where my solutions to these problems fail.
The questions are at this link (https://imgur.com/8wCo0DN)
I hope they’re readable.
1. Fill the cube
Here’s my solution to it:
I’ve put comments to guide you through the solution. I believe my macros are quite straight forward so that shouldn’t affect readability that much.
// Read this function after solve
int maxgap(vi &rem) {
// The goal of this function is to find the length of
// the largest square shaped empty space in the function.
int res = 0, n = rem.size();
foi(i, 0, n) {
foi(j, i, n) {
// i and j are the inclusive limiters for the current range
// curr is the square cavity in the range
int curr = INF;
// This loop calculates the limiting vertical space of the range
for (int x = i; x <= j; ++x) {
curr = min(curr, rem[x]);
}
// (j - i + 1) is the length of the range or the limiting horizontal space
curr = min(j - i + 1, curr);
res = max(res, curr);
}
}
return res;
}
void solve() {
int n; cin >> n;
vvi w(n, vi(n));
// Changing C's to 1 and D's to 0 to make the calculations ahead a bit simpler.
char temp;
foi(i, 0, n) {
foi(j, 0, n) {
cin >> temp;
if (temp == 'C') w[i][j] = 1;
else w[i][j] = 0;
}
}
// Only two rotations matter one "upright" and one "sideways".
// I calculate the number of bricks in each column in u and row in s.
// After that I change from number of bricks to number of empty spaces
vi u(n), s(n);
foi(i, 0, n) {
foi(j, 0, n) {
u[j] += w[i][j];
s[i] += w[i][j];
}
}
iter(i, u) i = n - i;
iter(i, s) i = n - i;
// Now read the maxgap function
cout << max(maxgap(u), maxgap(s));
}
2. Jogging ground
Here’s my solution to it:
It’s really straight forward python code so shouldn’t be a problem understanding it. I can’t see why this one would fail. Note that in the original solution I replaced dist with my own function because turns out python 3.6.x, the version used by the contest compiler didn’t have it
from math import sin, cos, radians, dist
r, d1, d2, d3 = [int(x) for x in input().split()]
angles = [int(x) for x in input().split()]
velocs = [int(x) for x in input().split()]
direcs = [1 if x == '1' else -1 for x in input().split()]
n = int(input())
a1, a2, a3, a4 = [angles[i] + (direcs[i]*velocs[i]*n)
for i in range(0, 4)]
def xyd(angle, radius, distance):
angle = radians(angle)
y = radius * sin(angle)
x = radius * cos(angle) + distance
return x, y
x1, y1 = xyd(a1, r, 0)
x2, y2 = xyd(a2, r, d1)
x3, y3 = xyd(a3, r, d2)
x4, y4 = xyd(a4, r, d3)
z1 = dist((x1, y1), (x2, y2))
z2 = dist((x2, y2), (x3, y3))
z3 = dist((x3, y3), (x4, y4))
print(round(z1 + z2 + z3), end="")
Both my solutions did pass the “Public” tests so am I missing something?

