제출 #48708

#제출 시각아이디문제언어결과실행 시간메모리
48708ExtazyTracks in the Snow (BOI13_tracks)C++17
15.52 / 100
2102 ms603512 KiB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 4007;
const pair < int, int > D[4] = {
  make_pair(1,0),
  make_pair(-1,0),
  make_pair(0,1),
  make_pair(0,-1)
};

int n,m;
char a[N][N];
bool used[N][N];
int ans;

void clear_used() {
  int i,j;

  for(i=1;i<=n;i++) {
    for(j=1;j<=m;j++) {
      used[i][j]=false;
    }
  }
}

void dfs(int r, int c, char ch) {
  a[r][c]='#';
  used[r][c]=true;

  int i,p,t;

  for(i=0;i<4;i++) {
    p=r+D[i].first;
    t=c+D[i].second;

    if(p>=1 && p<=n && t>=1 && t<=m) if(!used[p][t]) if(a[p][t]==ch || a[p][t]=='#') dfs(p,t,ch);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i,j;
  char curr;

  scanf("%d %d", &n, &m);
  for(i=1;i<=n;i++) {
    scanf("%s", a[i]+1);
  }

  curr=a[1][1];

  bool found=true;

  while(found) {
    found=false;

    for(i=1;!found && i<=n;i++) {
      for(j=1;!found && j<=m;j++) {
        if(a[i][j]==curr) {
          clear_used();
          dfs(i,j,a[i][j]);
          ++ans;

          if(curr=='R') curr='F';
          else curr='R';
          
          found=true;
        }
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", a[i]+1);
     ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...