Problem Info
Bucket Brigade, https://usaco.guide/general/expected#problem-usaco-939
My Work
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ifstream fin("buckets.in");
ofstream fout("buckets.out");
int b[2], r[2], l[2];
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 10; ++j) {
char c;
fin >> c;
if (c == 'B') {
*b = i;
*(b + 1) = j;
} else if (c == 'R') {
*r = i;
*(r + 1) = j;
} else if (c == 'L') {
*l = i;
*(l + 1) = j;
}
}
}
if ((((abs(*b - *l) == 1) && (*(b + 1) == *(l + 1))) || ((*b == *l) && (abs(*(b + 1) - *(l + 1)) == 1))) || ((*b == *r && *r == *l) && (*(l + 1) < *(r + 1) < *(b + 1) || *(b + 1) < *(r + 1) < *(l + 1))) || ((*(b + 1) == *(r + 1) && *(r + 1) == *(l + 1)) && (*l < *r < *b || *b < *r < *l))) {
fout << abs(*(l + 1) - *(b + 1)) + abs(*l - *b) + 1 << '\n';
} else {
fout << abs(*(l + 1) - *(b + 1)) + abs(*l - *b) - 1 << '\n';
}
return 0;
}
*b is vertical coordinate of B, *(b+1) is horizontal, with top left 0,0, and similar for R and L.
Long condition in words is:
if ( [(B,L vertically adjacent) or (B,L horizontally adjacent)] or [{(B,R,L have same ver coord) and (arranged as L…R…B or B…R…L)} or {(B,R,L have same hor coord) and (arranged as L…R…B or B…R…L but vertically)}] )
What I’ve Tried
I’ve tried many self-devised test cases, which all work (including special cases like B,L adjacent and R elsewhere, BRL adjacent etc.) but every time I run on USACO servers cases 6 and 7 are consistently wrong (rest pass), and so there’s probably a special case I’m missing that I’m failing to see. I’ll admit my logic in the last if condition is very unreadable, but having gone through it twice I can’t see an issue. (also apologies for the use of * everywhere, I learnt about pointers and wanted to test it, but ended up copy pasting similar parts and now it’s everywhere)
Question
Can anyone else spot said potentially missing special case, or any logic issue? Thank you in advance.