Submission #521958

# Submission time Handle Problem Language Result Execution time Memory
521958 2022-02-03T13:56:04 Z perchuts Tracks in the Snow (BOI13_tracks) C++17
100 / 100
778 ms 69572 KB
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
string grid[4000];
int h,w;
int a[8] = {-1,1,0,0,0,0,1,-1};
bool vis[4000][4000];
bool valid(int x,int y){return (x>=0&&x<h&&y>=0&&y<w);}

int bfs(){
    int ans = 0;
    queue<ii>q,qnext;
    bool type = grid[h-1][w-1]=='F';
    q.push({h-1,w-1});
    while(!q.empty()){
        while(!q.empty()){
            auto [x,y] = q.front();q.pop();
            for(int i=0;i<4;i++){
                int x2 = x+a[i], y2 = y+a[i+4]; 
                if(valid(x2,y2)&&!vis[x2][y2]&&grid[x2][y2]!='.'){
                    vis[x2][y2] = 1;
                    if(grid[x2][y2]==grid[x][y])q.push({x2,y2});
                    else qnext.push({x2,y2});
                }
            }
        }
        ans++;
        q = qnext;
        while(!qnext.empty())qnext.pop();
    }
  return ans;  
}



int main(){_
    cin>>h>>w;
    for(int i=0;i<h;i++)cin>>grid[i];
    cout<<bfs()<<endl;
}

Compilation message

tracks.cpp: In function 'int bfs()':
tracks.cpp:28:10: warning: unused variable 'type' [-Wunused-variable]
   28 |     bool type = grid[h-1][w-1]=='F';
      |          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2836 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 572 KB Output is correct
4 Correct 6 ms 2820 KB Output is correct
5 Correct 2 ms 1740 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 712 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 1484 KB Output is correct
11 Correct 2 ms 1360 KB Output is correct
12 Correct 5 ms 1828 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 3 ms 1732 KB Output is correct
15 Correct 11 ms 2864 KB Output is correct
16 Correct 14 ms 2976 KB Output is correct
17 Correct 8 ms 2764 KB Output is correct
18 Correct 7 ms 2872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15340 KB Output is correct
2 Correct 38 ms 8496 KB Output is correct
3 Correct 180 ms 49328 KB Output is correct
4 Correct 58 ms 15420 KB Output is correct
5 Correct 198 ms 30688 KB Output is correct
6 Correct 778 ms 69568 KB Output is correct
7 Correct 10 ms 16076 KB Output is correct
8 Correct 9 ms 15348 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 10 ms 15728 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 37 ms 8420 KB Output is correct
14 Correct 24 ms 5836 KB Output is correct
15 Correct 18 ms 6340 KB Output is correct
16 Correct 20 ms 3256 KB Output is correct
17 Correct 105 ms 16500 KB Output is correct
18 Correct 65 ms 16328 KB Output is correct
19 Correct 49 ms 15416 KB Output is correct
20 Correct 49 ms 14228 KB Output is correct
21 Correct 107 ms 31716 KB Output is correct
22 Correct 185 ms 30668 KB Output is correct
23 Correct 197 ms 26232 KB Output is correct
24 Correct 124 ms 31276 KB Output is correct
25 Correct 307 ms 49384 KB Output is correct
26 Correct 382 ms 39492 KB Output is correct
27 Correct 466 ms 52612 KB Output is correct
28 Correct 692 ms 69572 KB Output is correct
29 Correct 659 ms 66328 KB Output is correct
30 Correct 570 ms 63424 KB Output is correct
31 Correct 519 ms 34936 KB Output is correct
32 Correct 395 ms 50832 KB Output is correct