URAL 1525 Path
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const int maxn = 100000 + 10; char s[maxn]; int main() { long long int n, m, k; while (~scanf("%lld%lld%lld", &n, &m, &k)) { scanf("%s", s); int y = strlen(s); int i; long long int sum1 = 0, sum2 = 0, sum3 = 0; long long int maxn1 = 0, maxn2 = 0, maxn3 = 0, minn1 = 0, minn2 = 0, minn3 = 0; for (i = 0; i < y; i++) { if (s[i] == 'u') { sum1++; if (sum1 >= maxn1) maxn1 = sum1; } else if (s[i] == 'd') { sum1--; if (sum1 <= minn1) minn1 = sum1; } else if (s[i] == 'l') { sum2++; if (sum2 >= maxn2) maxn2 = sum2; } else if (s[i] == 'r') { sum2--; if (sum2 <= minn2) minn2 = sum2; } else if (s[i] == 'f') { sum3++; if (sum3 >= maxn3) maxn3 = sum3; } else if (s[i] == 'b') { sum3--; if (sum3 <= minn3) minn3 = sum3; } } long long int k1, k2, k3, ans; if (m - maxn1 + minn1 <= 1) m = 1; else m = m - maxn1 + minn1; if (n - maxn2 + minn2 <= 1) n = 1; else n = n - maxn2 + minn2; if (k - maxn3+ minn3 <= 1) k = 1; else k = k - maxn3 + minn3; printf("%lld\n", n*m*k); } return 0; }