답안 #625354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625354 2022-08-10T06:50:17 Z EthanKim8683 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
507 ms 128964 KB
#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

using I=int;
using C=char;
using B=bool;

const I H=4000;
const I W=4000;

I dx[4]{1,-1,0,0};
I dy[4]{0,0,1,-1};
C cels[H][W+1];
I deps[H][W];
deque<pair<I,I>>que;
I h,w;

B bnd(I i,I j){
  return i>=0&&i<h&&j>=0&&j<w;
}

void add1(I i,I j,I dep){
  deps[i][j]=dep;
  que.push_front({i,j});
}

void add2(I i,I j,I dep){
  deps[i][j]=dep+1;
  que.push_back({i,j});
}

I main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>h>>w;
  for(I i=0;i<h;i++)
    cin>>cels[i];
  add2(0,0,0);
  I res=1;
  while(que.size()){
    auto[i,j]=que.front();
    que.pop_front();
    I dep=deps[i][j];
    res=max(res,dep);
    for(I k=0;k<4;k++){
      I x=i+dx[k],y=j+dy[k];
      if(!bnd(x,y)||deps[x][y]>0||cels[x][y]=='.')continue;
      if(cels[i][j]==cels[x][y])add1(x,y,dep);
      else add2(x,y,dep);
    }
  }
  printf("%i\n",res);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 7 ms 5176 KB Output is correct
5 Correct 3 ms 2900 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 3 ms 2132 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 3 ms 2900 KB Output is correct
14 Correct 3 ms 2900 KB Output is correct
15 Correct 10 ms 5204 KB Output is correct
16 Correct 11 ms 5504 KB Output is correct
17 Correct 8 ms 5204 KB Output is correct
18 Correct 7 ms 5156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31064 KB Output is correct
2 Correct 36 ms 14992 KB Output is correct
3 Correct 169 ms 62676 KB Output is correct
4 Correct 56 ms 32476 KB Output is correct
5 Correct 136 ms 49884 KB Output is correct
6 Correct 505 ms 99548 KB Output is correct
7 Correct 18 ms 32508 KB Output is correct
8 Correct 16 ms 31000 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 18 ms 31588 KB Output is correct
12 Correct 1 ms 1620 KB Output is correct
13 Correct 38 ms 15000 KB Output is correct
14 Correct 21 ms 10536 KB Output is correct
15 Correct 21 ms 13000 KB Output is correct
16 Correct 17 ms 5688 KB Output is correct
17 Correct 91 ms 28460 KB Output is correct
18 Correct 66 ms 35480 KB Output is correct
19 Correct 56 ms 32288 KB Output is correct
20 Correct 44 ms 25036 KB Output is correct
21 Correct 104 ms 48980 KB Output is correct
22 Correct 141 ms 49688 KB Output is correct
23 Correct 175 ms 40584 KB Output is correct
24 Correct 111 ms 45588 KB Output is correct
25 Correct 291 ms 85356 KB Output is correct
26 Correct 311 ms 128964 KB Output is correct
27 Correct 407 ms 115484 KB Output is correct
28 Correct 507 ms 99128 KB Output is correct
29 Correct 484 ms 97428 KB Output is correct
30 Correct 466 ms 101892 KB Output is correct
31 Correct 429 ms 69288 KB Output is correct
32 Correct 361 ms 97312 KB Output is correct