using namespace std;
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long LL;
typedef pair<int,int> pii;
#define iter(x) x.begin(),x.end()
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
const int maxn = 805,mod = 0;
const LL inf = 1e9;
int arr[maxn];
void solve(){
int n,r,c;
string s;
cin >> n >> r >> c >> s;
bool toleft = false; int len = 0;
int tol = 0, tor = 0;
REP(2) for (auto &c:s){
if (c == 'E'){
if (toleft) tol = max(tol,++len);
else tol = max(tol,len = 1);
toleft = true;
}
else{
if (!toleft) tor = max(tor,++len);
else tor = max(tor,len = 1);
toleft = false;
}
}
if (!tol) tor = inf;
if (!tor) tol = inf;
int ans = inf,anscnt = 0;
REP(r){
REP1(i,c) cin >> arr[i];
REP1(st,c) if (arr[st]){
int l = st,r = st;
while (l > 1 and arr[l-1] and tol >= arr[l-1]) --l;
while (r < c and arr[r+1] and tor >= arr[r+1]) ++r;
if (r - l + 1 < ans){
ans = r - l + 1;
anscnt = 1;
}
else if (r - l + 1 == ans) ++anscnt;
//cerr << l << ',' << r << ' ';
}
//cerr << '\n';
}
cout << ans << '\n' << anscnt << '\n';
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
35 ms |
948 KB |
Output is correct |
3 |
Correct |
250 ms |
3860 KB |
Output is correct |
4 |
Correct |
166 ms |
1440 KB |
Output is correct |
5 |
Correct |
47 ms |
3912 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
344 ms |
1768 KB |
Output is correct |
8 |
Correct |
19 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
35 ms |
948 KB |
Output is correct |
3 |
Correct |
250 ms |
3860 KB |
Output is correct |
4 |
Correct |
166 ms |
1440 KB |
Output is correct |
5 |
Correct |
47 ms |
3912 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
344 ms |
1768 KB |
Output is correct |
8 |
Correct |
19 ms |
1868 KB |
Output is correct |
9 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |