## Submission #490097

# Submission time Handle Problem Language Result Execution time Memory
490097 2021-11-25T14:20:02 Z keertan Tracks in the Snow (BOI13_tracks) C++17
100 / 100
536 ms 118784 KB
```/**
* If you live in imaginary world when your imaginary situation encounter in
* real situation you can't enjoiy it because you have to do pending work.
* {This pending work appeared because you wasted that time for your useless
* imagianry thinking .}
*/
#include<bits/stdc++.h>
using namespace std;
//#define int  int64_t
#define all(x) x.begin(),x.end()
#define all1(x) x.rbegin(),x.rend()
#define sz(x) (int)(x.size())
const int N=4e5+5,mod=1e9+7;
vector<string> z(4000);
int dis[4000][4000];
vector<int> dx{1,-1,0,0},dy{0,0,1,-1};
void solve(){
int n,m;
cin>>n>>m;
for (int i=0;i<n;i++){cin>>z[i];}
int ans=1;
deque<pair<int,int>> q;
dis[0][0]=1;
q.push_back({0,0});
while(!q.empty()){
pair<int,int> u=q.front();
q.pop_front();
ans=max(ans,dis[u.first][u.second]);
for (int i=0;i<4;i++){
int x=u.first+dx[i],y=u.second+dy[i];
if (min(x,y)>=0 && x<n && y<m && z[x][y]!='.' && dis[x][y]==0){
if (z[u.first][u.second]==z[x][y]){
q.push_front({x,y});
dis[x][y]=dis[u.first][u.second];
}
else{
q.push_back({x,y});
dis[x][y]=dis[u.first][u.second]+1;
}
}
}
}
cout<<ans;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int tq=1;
//cin>>tq;
for (;tq;tq--){solve();}
}
//is a bruteforce possible?
//think greedier, make more assumptions
// if we you find solution using loop to decrease complexity use bs
//stuck for more than 5 minutes? move on  ```

#### Subtask #1 30.0 / 30.0

# Verdict Execution time Memory Grader output
1 Correct 11 ms 3532 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 6 ms 3276 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 3 ms 1612 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 9 ms 3404 KB Output is correct
16 Correct 10 ms 3532 KB Output is correct
17 Correct 7 ms 3404 KB Output is correct
18 Correct 6 ms 3276 KB Output is correct

#### Subtask #2 70.0 / 70.0

# Verdict Execution time Memory Grader output
1 Correct 12 ms 15820 KB Output is correct
2 Correct 39 ms 10360 KB Output is correct
3 Correct 169 ms 59752 KB Output is correct
4 Correct 55 ms 25608 KB Output is correct
5 Correct 135 ms 42852 KB Output is correct
6 Correct 534 ms 94404 KB Output is correct
7 Correct 10 ms 16508 KB Output is correct
8 Correct 10 ms 15744 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 10 ms 16204 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 36 ms 10416 KB Output is correct
14 Correct 25 ms 7104 KB Output is correct
15 Correct 18 ms 9352 KB Output is correct
16 Correct 17 ms 4300 KB Output is correct
17 Correct 98 ms 21284 KB Output is correct
18 Correct 66 ms 28200 KB Output is correct
19 Correct 56 ms 25632 KB Output is correct
20 Correct 43 ms 19036 KB Output is correct
21 Correct 103 ms 41356 KB Output is correct
22 Correct 148 ms 42828 KB Output is correct
23 Correct 181 ms 34808 KB Output is correct
24 Correct 102 ms 38508 KB Output is correct
25 Correct 318 ms 80580 KB Output is correct
26 Correct 353 ms 118784 KB Output is correct
27 Correct 405 ms 107264 KB Output is correct
28 Correct 536 ms 94284 KB Output is correct
29 Correct 516 ms 92760 KB Output is correct
30 Correct 475 ms 96976 KB Output is correct
31 Correct 446 ms 62168 KB Output is correct
32 Correct 369 ms 92544 KB Output is correct