제출 #742275

#제출 시각아이디문제언어결과실행 시간메모리
742275irmuunTracks in the Snow (BOI13_tracks)C++17
47.50 / 100
2136 ms1035556 KiB
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()

int h,w,cur;
string s[4005];
void dfs(int i,int j,char c){
    cur++;
    s[i][j]=(c=='R'?'F':'R');
    if(i>0&&s[i-1][j]==c){
        dfs(i-1,j,c);
    }
    if(i<h-1&&s[i+1][j]==c){
        dfs(i+1,j,c);
    }
    if(j>0&&s[i][j-1]==c){
        dfs(i,j-1,c);
    }
    if(j<w-1&&s[i][j+1]==c){
        dfs(i,j+1,c);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>h>>w;
    int cnt=0;
    for(int i=0;i<h;i++){
        cin>>s[i];
        for(int j=0;j<w;j++){
            if(s[i][j]!='.'){
                cnt++;
            }
        }
    }
    int ans=1;
    cur=0;
    dfs(0,0,s[0][0]);
    while(cur<cnt){
        cur=0;
        dfs(0,0,s[0][0]);
        ans++;
    }
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...