#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 |
1 |
Correct |
4 ms |
2932 KB |
Output is correct |
2 |
Correct |
43 ms |
8020 KB |
Output is correct |
3 |
Correct |
406 ms |
10316 KB |
Output is correct |
4 |
Correct |
217 ms |
7624 KB |
Output is correct |
5 |
Correct |
57 ms |
10316 KB |
Output is correct |
6 |
Correct |
5 ms |
4896 KB |
Output is correct |
7 |
Correct |
628 ms |
8276 KB |
Output is correct |
8 |
Correct |
35 ms |
6544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2932 KB |
Output is correct |
2 |
Correct |
43 ms |
8020 KB |
Output is correct |
3 |
Correct |
406 ms |
10316 KB |
Output is correct |
4 |
Correct |
217 ms |
7624 KB |
Output is correct |
5 |
Correct |
57 ms |
10316 KB |
Output is correct |
6 |
Correct |
5 ms |
4896 KB |
Output is correct |
7 |
Correct |
628 ms |
8276 KB |
Output is correct |
8 |
Correct |
35 ms |
6544 KB |
Output is correct |
9 |
Incorrect |
4 ms |
2340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |