Submission #479723

#TimeUsernameProblemLanguageResultExecution timeMemory
479723LptN21Zoo (COCI19_zoo)C++14
110 / 110
58 ms6232 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define PI acos(-1.0) #define FF first #define SS second #define eps 1e-9 // vector #define pb push_back #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define lb lower_bound #define ub upper_bound // bit #define CNTBIT(x) __builtin_popcount(x) #define ODDBIT(x) __builtin_parity(x) #define MASK(i) (1ll<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define MINBIT(x) (x)&(-x) // typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; typedef pair<int, ii> i3; /* CODE BELOW */ const int N=1e3+7, M=18; const int MOD=1e9+7; const int oo=1e9+9; int n, m, k, t; int tr[4]{-1, 0, 0, 1}; int tc[4]{0, -1, 1, 0}; int a[N][N]; bool mark[N][N]; int get(char c) { if(c=='T') return 1; if(c=='B') return 2; return 0; } bool check(int x, int y) { return (x>0&&y>0&&x<=n&&y<=m&&a[x][y]); } int bfs(int si, int sj) { queue<ii> q, nxtq; q.push(ii(si, sj)); int ui, uj, vi, vj, cnt=0; do{ cnt++; while(sz(q)) { tie(ui, uj)=q.front(), q.pop(); for(int i=0;i<4;i++) { vi=ui+tr[i], vj=uj+tc[i]; if(!check(vi, vj)||mark[vi][vj]) continue; mark[vi][vj]=1; if(a[ui][uj]==a[vi][vj]) q.push(ii(vi, vj)); else nxtq.push(ii(vi, vj)); } } while(sz(nxtq)) q.push(nxtq.front()), nxtq.pop(); }while(sz(q)); return cnt; } signed main() { //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); //fastIO; scanf("%d%d\n", &n, &m); char ch[m+1]; for(int i=1;i<=n;i++) { scanf("%s\n", &ch); for(int j=1;j<=m;j++) { a[i][j]=get(ch[j-1]); } } printf("%d", bfs(n, m)); return 0; } /* stuff you should look for - int overflow, array bounds - special/edge cases (n=1?) - do smth instead of nothing and stay organized - WRITE STUFF DOWN - DONT JUST STICK ON ONE APPROACH */

Compilation message (stderr)

zoo.cpp: In function 'int main()':
zoo.cpp:78:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[(m + 1)]' [-Wformat=]
   78 |         scanf("%s\n", &ch);
      |                ~^     ~~~
      |                 |     |
      |                 char* char (*)[(m + 1)]
zoo.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%d%d\n", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
zoo.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%s\n", &ch);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...