Submission #677779

#TimeUsernameProblemLanguageResultExecution timeMemory
677779puppyVirus Experiment (JOI19_virus)C++17
14 / 100
298 ms9036 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int arr[805][805]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int M, R, C; cin >> M >> R >> C; string s; cin >> s; s = s + s; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cin >> arr[i][j]; } } int wlim = 0, elim = 0; bool w = false, e = false; for (int i = 0; i < 2 * M; i++) { if (s[i] == 'W') w = true; else e = true; } if (!w) elim = 100001; if (!e) wlim = 100001; for (int i = 0; i < 2 * M; i++) { int st = i; while (i < 2 * M - 1 && s[i+1] == s[st]) ++i; int en = i; //[st, en] if (s[st] == 'W') wlim = max(wlim, en - st + 1); else elim = max(elim, en - st + 1); } int ans = 1e9, anscnt = 0; //왼쪽이 감염되어 있고 wlim보다 작거나 같으면 나도 감염됨 for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (arr[i][j] == 0) continue; int l = j, r = j; while (l > 0 && (arr[i][l-1] != 0 && arr[i][l-1] <= elim)) --l; while (r < C - 1 && arr[i][r+1] != 0 && arr[i][r+1] <= wlim) ++r; if (ans > r - l + 1) { ans = r - l + 1; anscnt = 1; } else if (ans == r - l + 1) { anscnt++; } } } cout << ans << '\n' << anscnt << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...