This was supposed to be one of the easy problems of Codex 3.0, infact it's solution is much simpler than you might imagine.
Here is the master solution in C:
#include <stdio.h>
long long MIN3(long long a,long long b,long long c)
{
if ( a < b && a < c ) return a;
else if ( b < c ) return b;
else return c;
}
int main()
{
int T;
long long l1, l2, l3, b1, b2, b3, l_min, b_min, ans, mod1, mod2, mod3;
scanf("%d",&T);
while ( T-- )
{
scanf("%lld %lld %lld %lld %lld %lld",&l1,&b1,&l2,&b2,&l3,&b3);
l_min = MIN3(l1,l2,l3);
b_min = MIN3(b1,b2,b3);
mod1=l1%3; mod2=l2%3; mod3=l3%3;
if (mod1 == mod2 || mod2 == mod3 || mod1 == mod3)
{
printf("0\n");
continue;
}
ans = l_min * ( b_min - (long long)((b_min-1)/3) - 1);
printf("%lld\n",ans);
}
return 0;
}
Here is the master solution in C:
#include <stdio.h>
long long MIN3(long long a,long long b,long long c)
{
if ( a < b && a < c ) return a;
else if ( b < c ) return b;
else return c;
}
int main()
{
int T;
long long l1, l2, l3, b1, b2, b3, l_min, b_min, ans, mod1, mod2, mod3;
scanf("%d",&T);
while ( T-- )
{
scanf("%lld %lld %lld %lld %lld %lld",&l1,&b1,&l2,&b2,&l3,&b3);
l_min = MIN3(l1,l2,l3);
b_min = MIN3(b1,b2,b3);
mod1=l1%3; mod2=l2%3; mod3=l3%3;
if (mod1 == mod2 || mod2 == mod3 || mod1 == mod3)
{
printf("0\n");
continue;
}
ans = l_min * ( b_min - (long long)((b_min-1)/3) - 1);
printf("%lld\n",ans);
}
return 0;
}
As you can see, the answer depends on minimum length and minimum breadth. But many people went for nested loops counting the number of squares that will be white. This counting approach is excessively time taking given the limits of input. So, naturally those attempts got TLE ( Time Limit Exceeded ).
No comments:
Post a Comment