Submission #477918

# Submission time Handle Problem Language Result Execution time Memory
477918 2021-10-04T15:30:57 Z Shogun3103 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
795 ms 131140 KB
#include <bits/stdc++.h>
 
using namespace std;

#define ll long long
#define ld long double
#define FOR(i,a,b) for(__typeof(b) i=a; i<=b; i++)
#define FOD(i,a,b) for(__typeof(b) i=b; i>=a; i--)
#define EACH(u, v) for(auto& u : v)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define iii pair<int,ii>
#define f first
#define s second
#define ed "\n"
#define sp " "
#define vi vector<int>
#define vii vector<ii>
#define vl vector<ll>
#define NO cout << "NO" << ed;
#define YES cout << "YES" << ed;
#define no cout << "no" << ed;
#define yes cout << "yes" << ed;

void setIO(string fileName = ""){
    if(fileName.length()){
        freopen((fileName+".in").c_str(), "r", stdin);
        freopen((fileName+".out").c_str(), "w", stdout);
    }
}

const int oo1 = 1e9 + 7;
const int oo2 = 1e9 + 9;
const int d4x[] = {0, 0, 1, -1};
const int d4y[] = {1, -1, 0, 0};
const int d8x[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int d8y[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int N = 4000 + 10;
const int M = 1e2 + 10;
vi adj[N];

int n, m, dep[N][N];
char a[N][N];

bool ok(int x, int y)
{
    return x && y && x <= n && y <= m && a[x][y] != '.';
}

void solve()
{
    cin >> n >> m;
    FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j];

    int ans = 0;
    deque<ii> q;
    q.pb({1, 1});
    dep[1][1] = 1;
    while(sz(q)) {
        ii cur = q.front();
        q.pop_front();
        ans = max(ans, dep[cur.f][cur.s]);
        FOR(i, 0, 3) {
            int x = cur.f + d4x[i];
            int y = cur.s + d4y[i];
            if(ok(x, y) && !dep[x][y]) {
                if(a[x][y] == a[cur.f][cur.s]) {
                    dep[x][y] = dep[cur.f][cur.s];
                    q.pf({x, y});
                } else {    
                    dep[x][y] = dep[cur.f][cur.s] + 1;
                    q.pb({x, y});
                }
            }
        }
    }
    cout << ans;
}

int main()
{ 
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);        
    setIO("");
    int t; t = 1;
    //int t; cin >> t;
    FOR(i, 1, t) {
        solve();
    }
    return 0;
}

Compilation message

tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((fileName+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen((fileName+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5464 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 12 ms 5304 KB Output is correct
5 Correct 4 ms 3020 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 4 ms 1228 KB Output is correct
10 Correct 5 ms 2508 KB Output is correct
11 Correct 5 ms 2252 KB Output is correct
12 Correct 7 ms 3136 KB Output is correct
13 Correct 4 ms 2984 KB Output is correct
14 Correct 4 ms 3020 KB Output is correct
15 Correct 18 ms 5300 KB Output is correct
16 Correct 15 ms 5552 KB Output is correct
17 Correct 12 ms 5292 KB Output is correct
18 Correct 9 ms 5292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 30892 KB Output is correct
2 Correct 59 ms 15136 KB Output is correct
3 Correct 378 ms 73352 KB Output is correct
4 Correct 118 ms 32732 KB Output is correct
5 Correct 295 ms 53484 KB Output is correct
6 Correct 780 ms 107812 KB Output is correct
7 Correct 19 ms 32332 KB Output is correct
8 Correct 18 ms 30948 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 18 ms 31692 KB Output is correct
12 Correct 2 ms 1612 KB Output is correct
13 Correct 63 ms 15204 KB Output is correct
14 Correct 39 ms 10464 KB Output is correct
15 Correct 34 ms 13200 KB Output is correct
16 Correct 26 ms 5828 KB Output is correct
17 Correct 156 ms 28720 KB Output is correct
18 Correct 122 ms 35748 KB Output is correct
19 Correct 104 ms 32696 KB Output is correct
20 Correct 89 ms 25596 KB Output is correct
21 Correct 242 ms 52676 KB Output is correct
22 Correct 274 ms 53444 KB Output is correct
23 Correct 274 ms 43764 KB Output is correct
24 Correct 208 ms 49904 KB Output is correct
25 Correct 562 ms 94512 KB Output is correct
26 Correct 711 ms 131140 KB Output is correct
27 Correct 719 ms 112808 KB Output is correct
28 Correct 795 ms 107736 KB Output is correct
29 Correct 771 ms 105400 KB Output is correct
30 Correct 777 ms 109880 KB Output is correct
31 Correct 559 ms 73692 KB Output is correct
32 Correct 727 ms 110632 KB Output is correct