Submission #598759

#TimeUsernameProblemLanguageResultExecution timeMemory
598759nguyen31hoang08minh2003Zoo (COCI19_zoo)C++14
0 / 110
1 ms332 KiB
#include <iostream> #include <fstream> #include <sstream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cctype> #include <cmath> #include <math.h> #include <string.h> #include <string> #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <bitset> #include <iterator> #include <functional> #include <algorithm> #include <cassert> #include <iomanip> #include <limits> #include <climits> #include <map> #include <ctime> #define fore(i, a, b) for(ll i = (a), _b = (b); i < (_b); i++) #define fort(i, a, b) for(ll i = (a), _b = (b); i <= (_b); i++) #define ford(i, a, b) for(ll i = (a), _b = (b); i >= (_b); i--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define pb push_back #define pf push_front #define fi first #define se second using namespace std; template<class T> bool mini(T &a, T b){return a > b ? (a = b, 1) : 0; } template<class T> bool maxi(T &a, T b){return a < b ? (a = b, 1) : 0; } typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; const ll maxN = 1e3 + 5; const ll maxM = 1e3 + 5; ll n,m; char c[maxN][maxM]; map<char,ll> cnt,cnt1; char curC; ull res; int t[4][2] = { {0,1}, {1,0}, {-1,0}, {0,-1} }; bool flag; queue<ii> q[2]; void spread(const ll x, const ll y){ c[x][y] = '^'; cnt[curC]--; ll u,v; fore(k,0,4){ u = x + t[k][0]; v = y + t[k][1]; if(u < 1 || v < 1 || u > n || v > m || c[u][v] == '*' || c[u][v] == '^') continue; if(c[u][v] == curC) spread(u,v); else q[!flag].push(ii(u,v)); } } void drawZoo(){ fort(i,1,n){ fort(j,1,m) cerr << c[i][j]; cerr << "\n"; } cerr << "\n"; } int main(){ #ifdef LOCAL freopen("input.INP","r",stdin); // freopen("output.OUT","w",stdout); #endif // LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; fort(i,1,n){ cin >> c[i] + 1; fort(j,1,m) if(c[i][j] != '*') cnt[c[i][j]]++; } curC = c[n][m]; q[0].push(ii(n,m)); while(cnt['B'] > 0 || cnt['T'] > 0){ for(;!q[flag].empty();q[flag].pop()){ spread(q[flag].front().fi, q[flag].front().se); } flag ^= 1; if(curC == 'T') curC = 'B'; else curC = 'T'; res++; } cout << res << '\n'; return 0; }

Compilation message (stderr)

zoo.cpp: In function 'int main()':
zoo.cpp:104:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  104 |         cin >> c[i] + 1;
      |                ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...