#include <bits/stdc++.h>
using namespace std;
int N, R, C;
int maxL, maxR;
int A[805][805];
string S;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N >> R >> C >> S; S += S;
for(int l = 0; l < R; l++)
for(int i = 0; i < C; i++)
cin >> A[l][i];
bool west = false, east = false;
for(int l = 0; l < N; l++)
west |= (S[l] == 'W'), east |= (S[l] == 'E');
if(!west) maxR = 100005;
if(!east) maxL = 100005;
for(int l = 0; l < 2 * N; l++) {
int i = l;
while(i + 1 < 2 * N && (S[i + 1] == S[l])) i++;
if(S[l] == 'W') maxL = max(maxL, i - l + 1);
if(S[l] == 'E') maxR = max(maxR, i - l + 1);
l = i;
}
int ans = 1e9 + 7, res = 0;
for(int l = 0; l < R; l++) {
for(int i = 0; i < C; i++) {
if(A[l][i] == 0) continue;
int x = i, y = i;
while(x + 1 < C && A[l][x + 1] != 0 && A[l][x + 1] <= maxL) x++;
while(y - 1 >= 0 && A[l][y - 1] != 0 && A[l][y - 1] <= maxR) y--;
int cur = x - y + 1;
if(cur < ans) ans = cur, res = 0;
if(cur == ans) res++;
}
}
cout << ans << "\n" << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
31 ms |
2772 KB |
Output is correct |
3 |
Correct |
203 ms |
3768 KB |
Output is correct |
4 |
Correct |
199 ms |
3916 KB |
Output is correct |
5 |
Correct |
42 ms |
4016 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
352 ms |
4208 KB |
Output is correct |
8 |
Correct |
17 ms |
3304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
31 ms |
2772 KB |
Output is correct |
3 |
Correct |
203 ms |
3768 KB |
Output is correct |
4 |
Correct |
199 ms |
3916 KB |
Output is correct |
5 |
Correct |
42 ms |
4016 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
352 ms |
4208 KB |
Output is correct |
8 |
Correct |
17 ms |
3304 KB |
Output is correct |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |