Submission #95320

#TimeUsernameProblemLanguageResultExecution timeMemory
95320Retro3014JOI 문장 (JOI14_ho_t1)C++17
100 / 100
77 ms2324 KiB
#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 = sum; 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]; pi = ii; pj = jj; break; } } } //* 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); //*/ ans = max(ans, sum2); c[i+pi][j+pj] = prv; } } printf("%d", ans); return 0; }

Compilation message (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:92:18: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
    c[i+pi][j+pj] = prv;
    ~~~~~~~~~~~~~~^~~~~
2014_ho_t1.cpp:92:13: warning: 'pj' may be used uninitialized in this function [-Wmaybe-uninitialized]
    c[i+pi][j+pj] = prv;
            ~^~~
2014_ho_t1.cpp:92:7: warning: 'pi' may be used uninitialized in this function [-Wmaybe-uninitialized]
    c[i+pi][j+pj] = prv;
      ~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...