Submission #484891

# Submission time Handle Problem Language Result Execution time Memory
484891 2021-11-05T17:31:44 Z ali22413836 Tracks in the Snow (BOI13_tracks) C++14
95.625 / 100
741 ms 223936 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[4000][4000] ;
ll vis[4000][4000] ;
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 = 0  ;
    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 6092 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 11 ms 5708 KB Output is correct
5 Correct 4 ms 3044 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 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 2612 KB Output is correct
11 Correct 3 ms 2332 KB Output is correct
12 Correct 5 ms 3280 KB Output is correct
13 Correct 3 ms 3020 KB Output is correct
14 Correct 3 ms 3148 KB Output is correct
15 Correct 10 ms 5760 KB Output is correct
16 Correct 11 ms 6096 KB Output is correct
17 Correct 12 ms 5836 KB Output is correct
18 Correct 10 ms 5708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 30772 KB Output is correct
2 Correct 37 ms 16708 KB Output is correct
3 Incorrect 22 ms 17348 KB Output isn't correct
4 Correct 78 ms 42648 KB Output is correct
5 Correct 125 ms 62408 KB Output is correct
6 Correct 565 ms 173872 KB Output is correct
7 Correct 17 ms 32120 KB Output is correct
8 Correct 19 ms 30728 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 18 ms 31564 KB Output is correct
12 Correct 1 ms 1612 KB Output is correct
13 Correct 36 ms 16676 KB Output is correct
14 Correct 21 ms 11544 KB Output is correct
15 Correct 21 ms 15984 KB Output is correct
16 Correct 19 ms 6640 KB Output is correct
17 Correct 87 ms 32364 KB Output is correct
18 Correct 78 ms 47164 KB Output is correct
19 Correct 63 ms 42684 KB Output is correct
20 Correct 42 ms 26948 KB Output is correct
21 Correct 102 ms 53760 KB Output is correct
22 Correct 128 ms 62440 KB Output is correct
23 Correct 168 ms 49996 KB Output is correct
24 Correct 111 ms 52676 KB Output is correct
25 Incorrect 26 ms 15916 KB Output isn't correct
26 Correct 741 ms 223936 KB Output is correct
27 Correct 516 ms 181472 KB Output is correct
28 Correct 560 ms 173772 KB Output is correct
29 Correct 552 ms 169920 KB Output is correct
30 Correct 568 ms 180196 KB Output is correct
31 Correct 445 ms 106828 KB Output is correct
32 Correct 495 ms 174484 KB Output is correct