Submission #770049

#TimeUsernameProblemLanguageResultExecution timeMemory
770049raysh07JOI 문장 (JOI14_ho_t1)C++17
100 / 100
93 ms2388 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n, m; const int N = 1005; string s[N], a[2]; int f(int i, int j){ if (i < 0 || i >= n - 1) return 0; if (j < 0 || j >= m - 1) return 0; return s[i][j] == a[0][0] && s[i + 1][j] == a[1][0] && s[i][j + 1] == a[0][1] && s[i + 1][j + 1] == a[1][1]; } int add(int i, int j, int x){ int ans = 0; ans += f(i, j); ans += f(i - 1, j); ans += f(i, j - 1); ans += f(i - 1, j - 1); return ans * x; } void Solve() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; cin >> a[0] >> a[1]; int ans = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ ans += f(i, j); } } int og = ans; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ char temp = s[i][j]; int curr = og; curr += add(i, j, -1); s[i][j] = 'J'; ans = max(ans, curr + add(i, j, 1)); s[i][j] = 'O'; ans = max(ans, curr + add(i, j, 1)); s[i][j] = 'I'; ans = max(ans, curr + add(i, j, 1)); s[i][j] = temp; } } cout << ans << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...