Submission #158977

# Submission time Handle Problem Language Result Execution time Memory
158977 2019-10-19T17:49:41 Z stefdasca Tracks in the Snow (BOI13_tracks) C++14
100 / 100
899 ms 43144 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

int n, m;
char c[4002][4002];
bool blocked[4002][4002];
int ans = 0;
int ox[] = {-1, 0, 1, 0};
int oy[] = {0, 1, 0, -1};
bool verif(int L, int C)
{
    return (L >= 1 && L <= n && C >= 1 && C <= m);
}
void lee(int L, int C)
{
    char init = c[L][C];
    c[L][C] = 'X';
    deque<pair<int, int> >d, d2;
    d.pb({L, C});
    while(!d.empty() || !d2.empty())
    {
        ++ans;
        while(!d.empty())
        {
            pair<int, int> poz = d[0];
            d.pop_front();
            for(int i = 0; i <= 3; ++i)
            {
                int X = poz.fi + ox[i];
                int Y = poz.se + oy[i];
                if(!verif(X, Y))
                    continue;
                if(c[X][Y] == 'X' || c[X][Y] == '.')
                    continue;
                if(blocked[X][Y])
                    continue;
                if(c[X][Y] == init)
                {
                    d.push_back({X, Y});
                    blocked[X][Y] = 1;
                }
                else
                {
                    d2.push_back({X, Y});
                    blocked[X][Y] = 1;
                }
            }
        }
        if(init == 'F')
            init = 'R';
        else
            init = 'F';
        swap(d, d2);
        for(int i = 0; i < d.size(); ++i)
        {
            pair<int, int> poz = d[0];
            c[poz.fi][poz.se] = 'X';
            blocked[poz.fi][poz.se] = 0;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> (c[i] + 1);
    lee(n, m);
    cout << ans;
    return 0;
}

Compilation message

tracks.cpp: In function 'void lee(int, int)':
tracks.cpp:91:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < d.size(); ++i)
                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4472 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 11 ms 4472 KB Output is correct
5 Correct 5 ms 2680 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 5 ms 2296 KB Output is correct
11 Correct 5 ms 2040 KB Output is correct
12 Correct 8 ms 2680 KB Output is correct
13 Correct 6 ms 2680 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 15 ms 4472 KB Output is correct
16 Correct 18 ms 4472 KB Output is correct
17 Correct 12 ms 4344 KB Output is correct
18 Correct 11 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 30328 KB Output is correct
2 Correct 53 ms 11724 KB Output is correct
3 Correct 218 ms 33016 KB Output is correct
4 Correct 68 ms 16888 KB Output is correct
5 Correct 179 ms 25208 KB Output is correct
6 Correct 899 ms 43144 KB Output is correct
7 Correct 34 ms 31736 KB Output is correct
8 Correct 32 ms 30328 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 33 ms 31164 KB Output is correct
12 Correct 3 ms 1500 KB Output is correct
13 Correct 53 ms 11716 KB Output is correct
14 Correct 32 ms 8440 KB Output is correct
15 Correct 24 ms 9336 KB Output is correct
16 Correct 25 ms 4088 KB Output is correct
17 Correct 138 ms 17912 KB Output is correct
18 Correct 89 ms 17784 KB Output is correct
19 Correct 69 ms 16888 KB Output is correct
20 Correct 59 ms 15864 KB Output is correct
21 Correct 137 ms 25980 KB Output is correct
22 Correct 179 ms 25080 KB Output is correct
23 Correct 267 ms 21312 KB Output is correct
24 Correct 135 ms 26104 KB Output is correct
25 Correct 371 ms 32888 KB Output is correct
26 Correct 523 ms 29048 KB Output is correct
27 Correct 668 ms 34680 KB Output is correct
28 Correct 853 ms 43144 KB Output is correct
29 Correct 838 ms 41352 KB Output is correct
30 Correct 730 ms 39904 KB Output is correct
31 Correct 804 ms 27064 KB Output is correct
32 Correct 587 ms 33528 KB Output is correct