| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1318580 | mibngor | Tracks in the Snow (BOI13_tracks) | C++20 | 619 ms | 293076 KiB |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define emp emplace_back
#define ins insert
#define fi first
#define se second
#define sz(x) x.size()
#define fop if(fopen("hello.inp","r")){freopen("hello.inp","r",stdin);freopen("hello.out","w",stdout);}
#define ls ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
ll Rd(ll l,ll r)
{
return uniform_int_distribution<int>(l,r)(rd);
}
const int N = 4e3 + 7;
int h,w,x[4] = {0,1,0,-1},y[4] = {1,0,-1,0},rs = 1;
bool vst[N][N];
char a[N][N];
void bfs(ll nx,ll ny)
{
deque<pair<int,int>> dq;
dq.push_back({nx,ny});
char cur = a[nx][ny];
while(!dq.empty())
{
auto u = dq.front();
dq.pop_front();
if(vst[u.fi][u.se])
continue;
vst[u.fi][u.se] = 1;
if(cur != a[u.fi][u.se])
{
rs++;
cur = a[u.fi][u.se];
}
for(int i = 0; i < 4; i++)
{
pair<int,int> v;
v.fi = u.fi + x[i];
v.se = u.se + y[i];
if(v.fi < 1 || v.fi > h)
continue;
if(v.se < 1 || v.se > h)
continue;
if(a[v.fi][v.se] == '.')
continue;
if(a[v.fi][v.se] != cur)
dq.push_back(v);
else dq.push_front(v);
}
}
}
main()
{
fop;
ls;
cin >> h >> w;
for(int i = 1; i <= h; i++)
for(int j = 1; j <= w; j++)
cin >> a[i][j];
bfs(1,1);
cout << rs;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
