제출 #762707

#제출 시각아이디문제언어결과실행 시간메모리
762707vjudge1바이러스 (JOI19_virus)C++17
14 / 100
1383 ms6672 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "C:\GCC\debug.h" #else #define debug(...) void(42) #endif const int inf = 123456780; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, r, c; cin >> n >> r >> c; vector<vector<int>> g(r, vector<int> (c)); string s; cin >> s; string t; t += s; t += s; swap(s, t); n *= 2; vector<pair<char, int>> buckets; for (int i = 0; i < n; i++) { if (!buckets.empty() && buckets.back().first == s[i]) { buckets.back().second += 1; } else { buckets.push_back({s[i], +1}); } } map<char, int> maxSubarray; for (int i = 0; i < (int) buckets.size(); i++) { maxSubarray[buckets[i].first] = max(maxSubarray[buckets[i].first], buckets[i].second); } if (maxSubarray['E'] == n) { maxSubarray['E'] = inf; } if (maxSubarray['W'] == n) { maxSubarray['W'] = inf; } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> g[i][j]; } } /* min and how many times it appears */ vector<int> row; auto Compute = [&](int x) { // suppose that x is infected, expand int low = x - 1; int high = x + 1; while (low >= 0 || high < c) { if (low >= 0 && maxSubarray['E'] >= row[low]) { --low; continue; } if (high < c && maxSubarray['W'] >= row[high]) { ++high; continue; } break; } int pts = high - low; pts--; return pts; }; int cnt = 0; int best = inf; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (g[i][j] == 0) { row.push_back(inf + 1); } else { row.push_back(g[i][j]); } } for (int j = 0; j < c; j++) { if (g[i][j] == 0) { continue; } int ret = Compute(j); if (ret < best) { best = ret; cnt = 1; } else if (ret == best) { ++cnt; } } row.clear(); } cout << best << " " << cnt << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...