Submission #715705

#TimeUsernameProblemLanguageResultExecution timeMemory
715705hamidh100Tracks in the Snow (BOI13_tracks)C++17
100 / 100
928 ms962152 KiB
/* 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...