Submission #715649

# Submission time Handle Problem Language Result Execution time Memory
715649 2023-03-27T11:45:26 Z fatemetmhr Tracks in the Snow (BOI13_tracks) C++17
100 / 100
419 ms 123452 KB
// ~ Be Name Khoda ~
 
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,O3")
 
using namespace std;
 
typedef long long ll;
 
#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
 
const int maxn  =  1e6   + 10;
const int maxn5 =  4e3   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  1e18;
 
int n, m, cnt = 0;
bool mark[maxn5][maxn5];
vector <pair<int, int>> nxt, tmp;
pair<int, int> q[maxn5 * maxn5];
string s[maxn5];
 
void bfs(int xx, int yy){
    int l = 0, r = 1;
    q[0] = {xx, yy};
    mark[xx][yy] = true;
    while(l < r){
        int x = q[l].fi, y = q[l].se;
        l++;
        if(x && !mark[x - 1][y] && s[x - 1][y] != '.'){
            if(s[x - 1][y] == s[x][y]){
                mark[x - 1][y] = true;
                q[r++] = {x - 1, y};
            }
            else
                nxt.pb({x - 1, y});
        }
        if(x + 1 < n && !mark[x + 1][y] && s[x + 1][y] != '.'){
            if(s[x + 1][y] == s[x][y]){
                mark[x + 1][y] = true;
                q[r++] = {x + 1, y};
            }
            else
                nxt.pb({x + 1, y});
        }
        if(y && !mark[x][y - 1] && s[x][y - 1] != '.'){
            if(s[x][y - 1] == s[x][y]){
                mark[x][y - 1] = true;
                q[r++] = {x, y - 1};
            }
            else
                nxt.pb({x, y - 1});
        }
        if(y + 1 < m && !mark[x][y + 1] && s[x][y + 1] != '.'){
            if(s[x][y + 1] == s[x][y]){
                mark[x][y + 1] = true;
                q[r++] = {x, y + 1};
            }
            else
                nxt.pb({x, y + 1});
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
 
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> s[i];
    bfs(0, 0);
    int ans = 1;
    while(nxt.size()){
        ans++;
        tmp.clear();
        for(auto u : nxt)
            tmp.pb(u);
        nxt.clear();
        for(auto u : tmp) if(!mark[u.fi][u.se])
            bfs(u.fi, u.se);
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3028 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 5 ms 3544 KB Output is correct
5 Correct 3 ms 1620 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1620 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 2 ms 1620 KB Output is correct
14 Correct 3 ms 1620 KB Output is correct
15 Correct 8 ms 2896 KB Output is correct
16 Correct 10 ms 3040 KB Output is correct
17 Correct 7 ms 2688 KB Output is correct
18 Correct 5 ms 3544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15384 KB Output is correct
2 Correct 28 ms 7132 KB Output is correct
3 Correct 123 ms 33876 KB Output is correct
4 Correct 45 ms 11856 KB Output is correct
5 Correct 108 ms 21984 KB Output is correct
6 Correct 399 ms 91408 KB Output is correct
7 Correct 11 ms 16084 KB Output is correct
8 Correct 10 ms 15444 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 14 ms 15848 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 29 ms 7124 KB Output is correct
14 Correct 18 ms 5204 KB Output is correct
15 Correct 10 ms 5436 KB Output is correct
16 Correct 16 ms 2760 KB Output is correct
17 Correct 69 ms 12852 KB Output is correct
18 Correct 36 ms 12500 KB Output is correct
19 Correct 35 ms 11868 KB Output is correct
20 Correct 38 ms 10964 KB Output is correct
21 Correct 85 ms 22704 KB Output is correct
22 Correct 108 ms 21992 KB Output is correct
23 Correct 155 ms 18908 KB Output is correct
24 Correct 81 ms 22480 KB Output is correct
25 Correct 253 ms 33872 KB Output is correct
26 Correct 318 ms 123452 KB Output is correct
27 Correct 344 ms 122916 KB Output is correct
28 Correct 419 ms 91536 KB Output is correct
29 Correct 379 ms 94480 KB Output is correct
30 Correct 382 ms 100624 KB Output is correct
31 Correct 391 ms 26104 KB Output is correct
32 Correct 261 ms 91024 KB Output is correct