This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 805;
int len, n, m, a[MN][MN];
string s;
int32_t main() {
boost();
cin >> len >> n >> m >> s;
while (s.length() < 1e6) s += s;
int me = 0, mw = 0, l = 0;
for (char c : s) {
if (c == 'E') l++;
else me = max(me, l), l = 0;
}
me = max(me, l);
l = 0;
for (char c : s) {
if (c == 'W') l++;
else mw = max(mw, l), l = 0;
}
mw = max(mw, l);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (!a[i][j]) a[i][j] = 0x3f3f3f3f;
}
}
int mn = 0x3f3f3f3f, cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 0x3f3f3f3f) continue;
int l = j, r = j;
while (1) {
if (l > 1 && a[i][l - 1] <= me) {
l--;
continue;
}
if (r < m && a[i][r + 1] <= mw) {
r++;
continue;
}
break;
}
if (r - l + 1 < mn) mn = r - l + 1, cnt = 1;
else if (r - l + 1 == mn) cnt++;
}
}
printf("%lld\n%lld\n", mn, cnt);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |