Submission #715705

# Submission time Handle Problem Language Result Execution time Memory
715705 2023-03-27T14:47:52 Z hamidh100 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
928 ms 962152 KB
/* In the name of God */

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <map>
#include <numeric>
#include <limits>
#include <limits.h>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef map<int, int> MPII;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define POP pop_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define Yes cout << "Yes\n"
#define YES cout << "YES\n"
#define No cout << "No\n"
#define NO cout << "NO\n"

const ll INF = (ll)2e18 + 1386;
const ld eps = 0.000000000000001;
const int MOD = 1e9 + 7;

inline int mod_(int a){ int res = a + MOD; return (res >= MOD? res - MOD : res); }
inline int mod_add(int a, int b){ int res = a + b; return (res >= MOD? res - MOD : res); }
inline int mod_neg(int a, int b){ int res = (abs(a - b) < MOD? a - b : (a - b) % MOD); return (res < 0? res + MOD : res); }
inline int mod_mlt(int a, int b){ return (1ll * a * b % MOD); }
inline string intToString(ll a){ char x[100]; sprintf(x, "%lld", a); string s = x; return s; }
inline ll stringToInt(string s){ ll res; char x[100]; strcpy(x, s.c_str()); sscanf(x, "%lld", &res); return res; }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }

const int MAXN = 4000;

int cmp, n, m;
VI nxt;
bitset<MAXN * MAXN> mark, a;

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

int get_id(int x, int y){
    return (x * m + y);
}

PII get_pos(int id){
    return MP(id / m, id % m);
}

void dfs(int x, int y){
    int tmpn = get_id(x, y);
    mark[tmpn] = 1;
    for (int i = 0; i < 4; i++){
        int xx = x + dx[i], yy = y + dy[i];
        int tmp = get_id(xx, yy);
        if (xx < n && xx >= 0 && yy >= 0 && yy < m && !mark[tmp]){
            if (a[tmp] ^ 1 == a[tmpn]){
                nxt.PB(tmp);
            }
            else if (a[tmp] == a[tmpn]) dfs(xx, yy);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            int id = get_id(i, j);
            char ch; cin >> ch;
            if (ch == 'F') a[id] = 0;
            else if (ch == 'R') a[id] = 1;
            else mark[id] = 1;
        }
    }
    nxt.PB(0);
    int lst = 0;
    while (true){
        int tmp = nxt.size();
        if (lst >= tmp) break;
        cmp++;
        for (int i = lst; i < tmp; i++){
            int x = get_pos(nxt[i]).first, y = get_pos(nxt[i]).second;
            if (!mark[nxt[i]]) dfs(x, y);
        }
        lst = tmp;
    }
    cout << cmp;
    return 0;
}

Compilation message

tracks.cpp: In function 'void dfs(int, int)':
tracks.cpp:83:28: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   83 |             if (a[tmp] ^ 1 == a[tmpn]){
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1620 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 3 ms 428 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 8 ms 984 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 16 ms 1592 KB Output is correct
16 Correct 23 ms 1816 KB Output is correct
17 Correct 12 ms 1124 KB Output is correct
18 Correct 7 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 53 ms 3016 KB Output is correct
3 Correct 392 ms 21524 KB Output is correct
4 Correct 85 ms 3708 KB Output is correct
5 Correct 242 ms 35924 KB Output is correct
6 Correct 760 ms 85236 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 52 ms 3024 KB Output is correct
14 Correct 31 ms 2852 KB Output is correct
15 Correct 26 ms 1884 KB Output is correct
16 Correct 29 ms 2836 KB Output is correct
17 Correct 148 ms 9936 KB Output is correct
18 Correct 98 ms 5848 KB Output is correct
19 Correct 82 ms 3696 KB Output is correct
20 Correct 83 ms 5704 KB Output is correct
21 Correct 222 ms 11652 KB Output is correct
22 Correct 285 ms 35864 KB Output is correct
23 Correct 273 ms 19248 KB Output is correct
24 Correct 218 ms 11260 KB Output is correct
25 Correct 425 ms 21348 KB Output is correct
26 Correct 928 ms 962152 KB Output is correct
27 Correct 713 ms 362740 KB Output is correct
28 Correct 717 ms 85224 KB Output is correct
29 Correct 723 ms 99388 KB Output is correct
30 Correct 699 ms 179188 KB Output is correct
31 Correct 783 ms 69364 KB Output is correct
32 Correct 732 ms 243836 KB Output is correct