Submission #762771

#TimeUsernameProblemLanguageResultExecution timeMemory
762771MohamedFaresNebiliVirus Experiment (JOI19_virus)C++14
0 / 100
1 ms468 KiB
#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) maxL = 100005; if(!east) maxR = 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...