Submission #1207885

#TimeUsernameProblemLanguageResultExecution timeMemory
1207885PlayVoltzJOI 문장 (JOI14_ho_t1)C++20
100 / 100
86 ms1352 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <chrono>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int dy[4]={0, 0, 1, 1};
int dx[4]={0, 1, 0, 1};
char flag[2][2], ooga[3]={'J', 'O', 'I'};
vector<string> vect;

int check(int i, int j){
	return vect[i][j]==flag[1][1]&&vect[i][j-1]==flag[1][0]&&vect[i-1][j]==flag[0][1]&&vect[i-1][j-1]==flag[0][0];
}

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, ori=0;
	cin>>n>>m;
	vect.resize(n);
	for (int i=0; i<n; ++i)cin>>vect[i];
	cin>>flag[0][0]>>flag[0][1]>>flag[1][0]>>flag[1][1];
	for (int i=1; i<n; ++i)for (int j=1; j<m; ++j)ori+=check(i, j);
	int ans=ori;
	for (int i=0; i<n; ++i)for (int j=0; j<m; ++j)for (int p=0; p<3; ++p){
		int res=0;
		for (int pp=0; pp<4; ++pp){
			int nx=i+dx[pp], ny=j+dy[pp];
			if (nx<1||ny<1||nx>=n||ny>=m)continue;
			res-=check(nx, ny);
			swap(vect[i][j], ooga[p]);
			res+=check(nx, ny);
			swap(vect[i][j], ooga[p]);
		}
		ans=max(ans, ori+res);
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...