제출 #910640

#제출 시각아이디문제언어결과실행 시간메모리
910640ByeWorldTracks in the Snow (BOI13_tracks)C++14
2.19 / 100
2098 ms311712 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #define bupol __builtin_popcount //#define int long long #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; const int MAXN = 2e5+5; const int MAXK = 205; const int LOG = 20; const int MOD = 1e9+7; const int SQRT = 520; const int INF = 1e9+10; typedef pair<ll,ll> pii; typedef pair<ll,pii> ipii; vector <int> dx = {-1, 0, 0, 1}; vector <int> dy = {0, -1, 1, 0}; int h, w; string s[4010]; bool vis[4010][4010]; int ans, cnt, tot; vector <pii> vec; char fnd; void bfs(){ int siz = vec.size(); for(int j=0; j<siz; j++){ int x = vec[j].fi, y = vec[j].se; for(int i=0; i<4; i++){ int nx = x+dx[i], ny = y+dy[i]; if(vis[nx][ny] || s[nx][ny] == '.') continue; if(s[nx][ny] == fnd){ vec.pb({nx, ny}); vis[nx][ny] = 1; cnt++; } } siz = vec.size(); } } signed main(){ //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> h >> w; for(int i=1; i<=h; i++){ cin >> s[i]; s[i] = '.'+s[i]+'.'; for(int j=1; j<=w; j++) if(s[i][j]!='.') tot++; } //cout << tot << " t\n"; for(int i=0; i<=w+1; i++){ s[0] += '.'; s[h+1] += '.'; } fnd = s[1][1]; vec.pb({1, 1}); vis[1][1] = 1; cnt = 1; while(cnt != tot){ ans++; bfs(); // if(fnd='F'){ // for(auto in : vec) cout << in.fi << ' '<< in.se << " p\n"; // exit(0); // } if(fnd=='R') fnd = 'H'; else fnd = 'R'; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...