제출 #449887

#제출 시각아이디문제언어결과실행 시간메모리
449887BT21tataTracks in the Snow (BOI13_tracks)C++17
0 / 100
1272 ms986724 KiB
#include<bits/stdc++.h> // #pragma GCC target ("avx,avx2,fma") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") typedef long long ll; typedef long double ld; #define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0) #define rall(v) (v).rbegin(),(v).rend() #define all(v) (v).begin(),(v).end() #define OK cerr<<"OK"<<endl<<flush #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define F first #define S second #define y0 jahdakdh #define y1 jahsadakdakdh #define endl '\n' using namespace std; const ll MOD=1e9+7; // mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count()); int n, m, ans; char a[4005][4005]; bool used[4005][4005]; void dfs(int x, int y) { used[x][y]=1; if(x+1<n and a[x+1][y]==a[x][y] and !used[x+1][y]) dfs(x+1, y); if(x-1>=0 and a[x-1][y]==a[x][y] and !used[x-1][y]) dfs(x-1, y); if(y+1<m and a[x][y+1]==a[x][y] and !used[x][y+1]) dfs(x, y+1); if(y-1>=0 and a[x][y-1]==a[x][y] and !used[x][y-1]) dfs(x, y-1); } int main() { SPEED; cin>>n>>m; for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin>>a[i][j]; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(a[i][j]==a[0][0] and !used[i][j]) ans++, dfs(i, j); } cout<<ans+1<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...