Is it possible to somehow see what tests exactly my code does not pass? I am pretty sure my solution is correct and when I check it on my own, the results are correct in all cases. How can I check what fails?
#include <stdio.h>
#include <stdbool.h>
int min(int a, int b) {
return (a < b) ? a : b;
}
int max(int a, int b) {
return (a > b) ? a : b;
}
int count_red_squares(int xld, int yld, int xpg, int ypg) {
int red_count = 0;
for (int y = yld; y < ypg; y++) {
if (y % 2 == 1) {
int max_x = min(y, xpg - 1);
if (max_x >= xld) {
red_count += max_x - xld + 1;
}
}
int start_x = max(y + 1, xld);
if (start_x < xpg) {
start_x += (start_x % 2 == 0);
if (start_x < xpg) {
int count_odds = (xpg - start_x + 1) / 2;
red_count += count_odds;
}
}
}
return red_count;
}
bool check_input_validity(int xld, int yld, int xpg, int ypg) {
if (xld < 0 || yld < 0 || xpg < 0 || ypg < 0) {
printf("xld, yld, xpg and ypg should be positive integers\n");
return false;
}
if (xld > xpg || yld > ypg) {
printf("xld and yld should be less than xpg and ypg\n");
return false;
}
if (xld > 1000000 || yld > 1000000 || xpg > 1000000 || ypg > 1000000) {
printf("xld, yld, xpg and ypg should be less than 1000000\n");
return false;
}
return true;
}
int main() {
int xld, yld, xpg, ypg;
bool is_input_valid = false;
while (!is_input_valid) {
scanf("%d %d %d %d", &xld, &yld, &xpg, &ypg);
is_input_valid = check_input_validity(xld, yld, xpg, ypg);
}
printf("%d", count_red_squares(xld, yld, xpg, ypg));
return 0;
}
created
last reply
- 1
reply
- 24
views
- 2
users