Submission #1287352

#TimeUsernameProblemLanguageResultExecution timeMemory
1287352keremJOI 문장 (JOI14_ho_t1)C++20
100 / 100
112 ms1416 KiB
#include <bits/stdc++.h>
using namespace std;
//~ #define int int64_t
#define pb push_back
#define emb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define sp << " " <<
#define N 1000
#define inf (int)1e9
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;

int n,m;
char tt[2][2],a[N][N];
int chk(int x,int y){
	if(x<0 || n-1<=x || y<0 || m-1<=y) return 0;
	if(a[x][y]!=tt[0][0]) return 0;
	if(a[x][y+1]!=tt[0][1]) return 0;
	if(a[x+1][y]!=tt[1][0]) return 0;
	if(a[x+1][y+1]!=tt[1][1]) return 0;
	return 1;
}
int calc(int x,int y,char c){
	int pre=0,aft=0;
	char prec=a[x][y];
	pre+=chk(x,y)+chk(x,y-1)+chk(x-1,y)+chk(x-1,y-1);
	a[x][y]=c;
	aft+=chk(x,y)+chk(x,y-1)+chk(x-1,y)+chk(x-1,y-1);
	a[x][y]=prec;
	return aft-pre;
}
void solve(){
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	cin >> tt[0][0] >> tt[0][1] >> tt[1][0] >> tt[1][1];
	int ans=0;
	for(int i=0;i<n-1;i++)
		for(int j=0;j<m-1;j++)
			ans+=chk(i,j);
	int t=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			t=max(t,calc(i,j,'J'));
			t=max(t,calc(i,j,'O'));
			t=max(t,calc(i,j,'I'));
		}
	}
	cout << ans+t << endl;
}
int32_t main(){
	//~ freopen("hopscotch.in","r",stdin);
	//~ freopen("hopscotch.out","w",stdout);
	
	cout << fixed << setprecision(0);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int test=1;
	//~ cin >> test;
	while(test--) solve();
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...