Submission #490098

# Submission time Handle Problem Language Result Execution time Memory
490098 2021-11-25T14:21:22 Z keertan Tracks in the Snow (BOI13_tracks) C++17
100 / 100
524 ms 118748 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.emplace_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.emplace_front(x,y);
dis[x][y]=dis[u.first][u.second];
}
else{
q.emplace_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 10 ms 3660 KB Output is correct
2 Correct 1 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 1 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 2 ms 1612 KB Output is correct
11 Correct 3 ms 1452 KB Output is correct
12 Correct 4 ms 1996 KB Output is correct
13 Correct 3 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 9 ms 3364 KB Output is correct
16 Correct 10 ms 3660 KB Output is correct
17 Correct 8 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 11 ms 15788 KB Output is correct
2 Correct 34 ms 10340 KB Output is correct
3 Correct 162 ms 59776 KB Output is correct
4 Correct 56 ms 25668 KB Output is correct
5 Correct 130 ms 42804 KB Output is correct
6 Correct 508 ms 94136 KB Output is correct
7 Correct 11 ms 16460 KB Output is correct
8 Correct 10 ms 15820 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 16 ms 16160 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 33 ms 10348 KB Output is correct
14 Correct 20 ms 7104 KB Output is correct
15 Correct 20 ms 9292 KB Output is correct
16 Correct 17 ms 4276 KB Output is correct
17 Correct 85 ms 21188 KB Output is correct
18 Correct 64 ms 28152 KB Output is correct
19 Correct 58 ms 25580 KB Output is correct
20 Correct 44 ms 19012 KB Output is correct
21 Correct 103 ms 41428 KB Output is correct
22 Correct 104 ms 42788 KB Output is correct
23 Correct 188 ms 34884 KB Output is correct
24 Correct 95 ms 38516 KB Output is correct
25 Correct 282 ms 80676 KB Output is correct
26 Correct 332 ms 118748 KB Output is correct
27 Correct 435 ms 107320 KB Output is correct
28 Correct 503 ms 94228 KB Output is correct
29 Correct 524 ms 92724 KB Output is correct
30 Correct 462 ms 96916 KB Output is correct
31 Correct 460 ms 62024 KB Output is correct
32 Correct 358 ms 92544 KB Output is correct