Submission #499323

# Submission time Handle Problem Language Result Execution time Memory
499323 2021-12-28T02:53:22 Z tphuc2908 Tracks in the Snow (BOI13_tracks) C++14
0 / 100
1699 ms 151748 KB
#include<bits/stdc++.h>

using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
//#define int long long
typedef long long ll;
typedef vector<int> vi;
const int N = 4e3 + 5;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int pi = 31;
const int inf = 1e9 + 5;
const int block = 330;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

void readfile(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("text.inp", "r", stdin);
    #endif // ONLINE_JUDGE
//    freopen("248.in", "r", stdin);
//    freopen("248.out", "w", stdout);
}

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

void inp(){
    cin >> n >> m;
    rep(i,1,n)
        rep(j,1,m)
            cin >> a[i][j];
}

queue<pair<int,int> > q[2];
int d[N][N], vis[N][N];

void bfs(int x, int y){
    rep(i,1,n)
        rep(j,1,m)
            d[i][j] = inf;
    d[x][y] = 0;
    q[0].push(mp(x, y));
    int num = 1, pos = 0;
    while(num){
        while(q[pos % 2].empty())
            ++pos;
        auto top = q[pos % 2].front();
        q[pos % 2].pop(), --num;
        if(vis[top.fi][top.se]) continue;
        vis[top.fi][top.se] = 1;
        rep(i,0,3){
            int x = top.fi + dx[i];
            int y = top.se + dy[i];
            if(1 <= x && x <= n && 1 <= y && y <= m && a[x][y]!='.'){
                int cost = (a[x][y] != a[top.fi][top.se]);
                if(d[x][y] > d[top.fi][top.se] + cost){
                    d[x][y] = d[top.fi][top.se] + cost;
                    q[d[x][y] % 2].push(mp(x, y));
                    ++num;
                }
            }
        }
    }
}

void process(){
    bfs(1,1);
    int res = 0;
    rep(i,1,n)
        rep(j,1,m)
            if(d[i][j]!=inf)
                res = max(res, d[i][j]);
    cout << res;
}

int main() {
  //  readfile();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    TC(t){
        inp();
        process();
//    }
    return 0;
}

Compilation message

tracks.cpp: In function 'void readfile()':
tracks.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 8456 KB Output isn't correct
2 Incorrect 1 ms 460 KB Output isn't correct
3 Incorrect 1 ms 844 KB Output isn't correct
4 Incorrect 13 ms 7632 KB Output isn't correct
5 Incorrect 8 ms 4428 KB Output isn't correct
6 Incorrect 1 ms 536 KB Output isn't correct
7 Incorrect 1 ms 844 KB Output isn't correct
8 Incorrect 1 ms 972 KB Output isn't correct
9 Incorrect 2 ms 1484 KB Output isn't correct
10 Incorrect 5 ms 3660 KB Output isn't correct
11 Incorrect 4 ms 3088 KB Output isn't correct
12 Incorrect 7 ms 4560 KB Output isn't correct
13 Incorrect 4 ms 4420 KB Output isn't correct
14 Incorrect 5 ms 4436 KB Output isn't correct
15 Incorrect 20 ms 8144 KB Output isn't correct
16 Incorrect 21 ms 8292 KB Output isn't correct
17 Incorrect 19 ms 7988 KB Output isn't correct
18 Incorrect 12 ms 7708 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 46412 KB Output isn't correct
2 Incorrect 80 ms 24952 KB Output isn't correct
3 Incorrect 404 ms 120772 KB Output isn't correct
4 Incorrect 139 ms 51448 KB Output isn't correct
5 Incorrect 292 ms 91760 KB Output isn't correct
6 Incorrect 1694 ms 151748 KB Output isn't correct
7 Incorrect 21 ms 48460 KB Output isn't correct
8 Incorrect 27 ms 46420 KB Output isn't correct
9 Incorrect 3 ms 892 KB Output isn't correct
10 Incorrect 1 ms 452 KB Output isn't correct
11 Incorrect 22 ms 47556 KB Output isn't correct
12 Incorrect 2 ms 2232 KB Output isn't correct
13 Incorrect 103 ms 24848 KB Output isn't correct
14 Incorrect 45 ms 16856 KB Output isn't correct
15 Incorrect 48 ms 20192 KB Output isn't correct
16 Incorrect 33 ms 9280 KB Output isn't correct
17 Incorrect 249 ms 48980 KB Output isn't correct
18 Incorrect 172 ms 55624 KB Output isn't correct
19 Incorrect 139 ms 51452 KB Output isn't correct
20 Incorrect 96 ms 42800 KB Output isn't correct
21 Incorrect 247 ms 92460 KB Output isn't correct
22 Incorrect 273 ms 91724 KB Output isn't correct
23 Incorrect 404 ms 75584 KB Output isn't correct
24 Incorrect 244 ms 89168 KB Output isn't correct
25 Incorrect 749 ms 141480 KB Output isn't correct
26 Incorrect 983 ms 123976 KB Output isn't correct
27 Incorrect 1481 ms 143216 KB Output isn't correct
28 Incorrect 1699 ms 151676 KB Output isn't correct
29 Incorrect 1623 ms 150112 KB Output isn't correct
30 Incorrect 1450 ms 146508 KB Output isn't correct
31 Incorrect 1068 ms 113728 KB Output isn't correct
32 Incorrect 1259 ms 142240 KB Output isn't correct