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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 800 + 10;
const int maxm = 1e5 + 10;
int m, r, c, a[maxn][maxn], dp[maxn][maxn];
string s;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> m >> r >> c >> s;
for (int i = 1; i <= r; i++){
for (int j = 1; j <= c; j++){
cin >> a[i][j];
}
}
while(s.size() < 100000){
s += s;
}
m = s.size();
int mxl = 0, cnt = 0;
for (int i = 0; i < m; i++){
if (s[i] == 'E') cnt++;
else cnt = 0;
mxl = max(mxl, cnt);
}
int mxr = 0; cnt = 0;
for (int i = 0; i < m; i++){
if (s[i] == 'W') cnt++;
else cnt = 0;
mxr = max(mxr, cnt);
}
pii ans = {r*c, 0};
for (int k = 1; k <= r; k++){
for (int i = 1; i <= c; i++){
for (int j = c; j >= i; j--){
dp[i][j] = j - i + 1;
if (i > 1 && a[k][i-1] != 0 && a[k][i-1] <= mxl) dp[i][j] = dp[i-1][j];
else if (j < c && a[k][j+1] != 0 && a[k][j+1] <= mxr) dp[i][j] = dp[i][j+1];
}
if (a[k][i] == 0) continue;
//debug(k, i, dp[i][i]);
if (ans.F > dp[i][i]){
ans.F = dp[i][i];
ans.S = 1;
}
else if(ans.F == dp[i][i]) ans.S++;
}
}
cout << ans.F << '\n' << ans.S << '\n';
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... |