이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define MAX_N 1000
using namespace std;
int N, M;
char c[MAX_N+1][MAX_N+1];
char ch[2][2];
int sum;
int ans;
int differ(int x, int y){
int ret=0;
if(x>=N || y>=M) return -1;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
if(c[x+i][y+j]!=ch[i][j]) ret++;
}
}
return ret;
}
bool same(int x, int y){
return (differ(x, y)==0);
}
int main(){
scanf("%d%d", &N, &M);
for(int i=0; i<N; i++){
getchar();
for(int j=0; j<M; j++){
scanf("%c", &c[i][j]);
//printf("%c", c[i][j]);
}//cout<<endl;
}
for(int i=0; i<2; i++){
getchar();
for(int j=0; j<2; j++) {
scanf("%c", &ch[i][j]);
//printf("%c", ch[i][j]);
}//cout<<endl;
}
for(int i=0; i<N-1; i++){
for(int j=0; j<M-1; j++){
sum+=same(i, j);
}
}
//cout<<sum<<endl;
ans = max(ans, sum);
int sum2;
for(int i=0; i<N-1; i++){
for(int j=0; j<M-1; j++){
if(differ(i, j)!=1) continue;
sum2 = 0;
int ii, jj;
int pi, pj;
/*
for(ii=max(0, i-1); ii<min(N-1,i+2); ii++){
for(jj=max(0, j-1); jj<min(M-1, j+2); jj++){
sum2-=same(ii, jj);
}
}
//*/
char prv;
for(ii=0; ii<2; ii++){
for(jj=0; jj<2; jj++){
if(c[i+ii][j+jj]!=ch[ii][jj]){
prv = c[i+ii][j+jj];
c[i+ii][j+jj] = ch[ii][jj];
break;
}
}
}
pi = ii; pj = jj;
/*
for(ii=max(0, i-1); ii<min(N-1,i+2); ii++){
for(jj=max(0, j-1); jj<min(M-1, j+2); jj++){
//cout<<ii<<" "<<jj<<" "<<same(ii, jj)<<endl;
sum2+=same(ii, jj);
}
}
//printf("%d %d %d\n", i, j, sum2);
//*/
for(ii=0; ii<N-1; ii++){
for(jj=0; jj<M-1; jj++){
sum2+=same(ii, jj);
}
}
ans = max(ans, sum2);
c[i+pi][j+pj] = prv;
}
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
2014_ho_t1.cpp: In function 'int main()':
2014_ho_t1.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
2014_ho_t1.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &c[i][j]);
~~~~~^~~~~~~~~~~~~~~~
2014_ho_t1.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &ch[i][j]);
~~~~~^~~~~~~~~~~~~~~~~
2014_ho_t1.cpp:97:18: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
c[i+pi][j+pj] = prv;
~~~~~~~~~~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |