Submission #531631

#TimeUsernameProblemLanguageResultExecution timeMemory
531631Tam_theguideTracks in the Snow (BOI13_tracks)C++14
2.19 / 100
1715 ms798828 KiB
#include <bits/stdc++.h> using namespace std; int n, m; char a[4005][4005]; char last; const int dx[4]={0, 0, 1, -1}; const int dy[4]={1, -1, 0, 0}; bool visited[4005][4005]; int ans=0; bool check(int i, int j){ if (1<=i && i<=n && 1<=j && j<=m) return true; else return false; } void floodfill(int i, int j){ if (check(i, j)==false || visited[i][j]) return; visited[i][j]=true; for (int t=0; t<4; t++){ int u=i+dx[t]; int v=j+dy[t]; floodfill(u, v); } } int main(){ cin>>n>>m; for (int i=1;i <=n; i++){ for (int j=1; j<=m; j++){ cin>>a[i][j]; if (i==1 && j==1){ last=a[i][j]; } if (a[i][j]!=last && a[i][j]!='.'){ ans=1; } } } for (int i=1;i <=n; i++){ for (int j=1; j<=m; j++){ if (a[i][j]==last && visited[i][j]==false){ ans++; floodfill(i, j); } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...