Submission #484898

# Submission time Handle Problem Language Result Execution time Memory
484898 2021-11-05T17:43:13 Z ali22413836 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
610 ms 224120 KB
#include <bits/stdc++.h>
#define  endl "\n"
using namespace std ;
typedef long long ll;
typedef long double ld ;
const int N=2e7;
const ll inf=1e18 ;
const ll mod = 1e9 + 7 ;
ll mypower(ll x, ll y){
    if(y == 0) return 1 ;
    if(y == 1) return x ;
    ll ret = mypower(x , y / 2);
    ret = (ret * ret) % mod;
    if(y % 2) ret = ( ret * x ) % mod ;
    return ret ;
}
ll n , m ;
char a[4009][4009] ;
ll vis[4009][4009] ;
ll sta , sta2 , en , en2 ;
ll di[] = {0 , 0 , 1 , -1} , di2[] = {1 , -1 , 0 , 0} ;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m ;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] ;
    }
    deque < pair < ll , ll > > q ;
    q.push_back({sta , sta2}) ;
    sta = 0 , sta2 =  0 ;
    vis[sta][sta2] = 1 ;
    ll ans = 1 ;
    while(!q.empty()){
        pair < ll , ll > x  ;
        x = q.front() ;
        q.pop_front() ;
        ans = max(ans , vis[x.first][x.second])  ;
        ll i = x.first , j = x.second ;
        for(int k = 0 ; k < 4 ; k++){
            ll ni = i + di[k] , nj = j + di2[k] ;
            if(ni < n && ni >= 0 && nj < m && nj >= 0 && a[ni][nj] != '.' && vis[ni][nj] == 0){
                if(a[ni][nj] == a[i][j]){
                    q.push_front({ni , nj}) ;
                    vis[ni][nj] = vis[i][j]  ;
                }
                else{
                    q.push_back({ni , nj}) ;
                    vis[ni][nj] = vis[i][j] + 1 ;
                }
             }
        }
    }
    cout << ans << endl ;
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6220 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 716 KB Output is correct
4 Correct 7 ms 5836 KB Output is correct
5 Correct 3 ms 3148 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 716 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 3 ms 2508 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 5 ms 3264 KB Output is correct
13 Correct 3 ms 3148 KB Output is correct
14 Correct 3 ms 3148 KB Output is correct
15 Correct 9 ms 5708 KB Output is correct
16 Correct 11 ms 6148 KB Output is correct
17 Correct 8 ms 5812 KB Output is correct
18 Correct 7 ms 5836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 30924 KB Output is correct
2 Correct 35 ms 16676 KB Output is correct
3 Correct 151 ms 75728 KB Output is correct
4 Correct 61 ms 42820 KB Output is correct
5 Correct 122 ms 62488 KB Output is correct
6 Correct 555 ms 167876 KB Output is correct
7 Correct 17 ms 32460 KB Output is correct
8 Correct 16 ms 30916 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 31748 KB Output is correct
12 Correct 1 ms 1612 KB Output is correct
13 Correct 35 ms 16636 KB Output is correct
14 Correct 20 ms 11504 KB Output is correct
15 Correct 25 ms 16052 KB Output is correct
16 Correct 18 ms 6640 KB Output is correct
17 Correct 86 ms 32264 KB Output is correct
18 Correct 79 ms 47396 KB Output is correct
19 Correct 62 ms 42772 KB Output is correct
20 Correct 42 ms 27012 KB Output is correct
21 Correct 97 ms 53956 KB Output is correct
22 Correct 126 ms 62416 KB Output is correct
23 Correct 160 ms 49920 KB Output is correct
24 Correct 93 ms 52804 KB Output is correct
25 Correct 388 ms 141504 KB Output is correct
26 Correct 524 ms 224120 KB Output is correct
27 Correct 610 ms 177996 KB Output is correct
28 Correct 559 ms 167936 KB Output is correct
29 Correct 541 ms 163292 KB Output is correct
30 Correct 560 ms 173240 KB Output is correct
31 Correct 510 ms 106668 KB Output is correct
32 Correct 609 ms 168256 KB Output is correct