Submission #477980

# Submission time Handle Problem Language Result Execution time Memory
477980 2021-10-05T00:15:13 Z Shogun3103 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
806 ms 119280 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 15 ms 5252 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 9 ms 5068 KB Output is correct
5 Correct 4 ms 2892 KB Output is correct
6 Correct 0 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 1228 KB Output is correct
10 Correct 3 ms 2508 KB Output is correct
11 Correct 3 ms 2124 KB Output is correct
12 Correct 6 ms 3020 KB Output is correct
13 Correct 4 ms 2892 KB Output is correct
14 Correct 4 ms 2892 KB Output is correct
15 Correct 16 ms 5092 KB Output is correct
16 Correct 14 ms 5236 KB Output is correct
17 Correct 11 ms 5068 KB Output is correct
18 Correct 9 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 30880 KB Output is correct
2 Correct 55 ms 13580 KB Output is correct
3 Correct 364 ms 57636 KB Output is correct
4 Correct 127 ms 29052 KB Output is correct
5 Correct 248 ms 44820 KB Output is correct
6 Correct 754 ms 92016 KB Output is correct
7 Correct 17 ms 32204 KB Output is correct
8 Correct 17 ms 30844 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 16 ms 31692 KB Output is correct
12 Correct 2 ms 1612 KB Output is correct
13 Correct 61 ms 13692 KB Output is correct
14 Correct 36 ms 9668 KB Output is correct
15 Correct 34 ms 12256 KB Output is correct
16 Correct 25 ms 5140 KB Output is correct
17 Correct 143 ms 24820 KB Output is correct
18 Correct 133 ms 31844 KB Output is correct
19 Correct 105 ms 29124 KB Output is correct
20 Correct 90 ms 22276 KB Output is correct
21 Correct 222 ms 43484 KB Output is correct
22 Correct 249 ms 44816 KB Output is correct
23 Correct 266 ms 36092 KB Output is correct
24 Correct 224 ms 41028 KB Output is correct
25 Correct 575 ms 78804 KB Output is correct
26 Correct 781 ms 119280 KB Output is correct
27 Correct 707 ms 97312 KB Output is correct
28 Correct 800 ms 92200 KB Output is correct
29 Correct 798 ms 89792 KB Output is correct
30 Correct 806 ms 94600 KB Output is correct
31 Correct 560 ms 63556 KB Output is correct
32 Correct 702 ms 95096 KB Output is correct