답안 #479723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479723 2021-10-13T01:36:07 Z LptN21 Zoo (COCI19_zoo) C++14
110 / 110
58 ms 6232 KB
#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

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);
      |         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 816 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 692 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 816 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 692 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 12 ms 6092 KB Output is correct
17 Correct 13 ms 6072 KB Output is correct
18 Correct 12 ms 6232 KB Output is correct
19 Correct 14 ms 6104 KB Output is correct
20 Correct 13 ms 6036 KB Output is correct
21 Correct 58 ms 5836 KB Output is correct
22 Correct 53 ms 6008 KB Output is correct
23 Correct 53 ms 5964 KB Output is correct
24 Correct 55 ms 6064 KB Output is correct
25 Correct 54 ms 6092 KB Output is correct
26 Correct 52 ms 5924 KB Output is correct
27 Correct 52 ms 5912 KB Output is correct
28 Correct 53 ms 5940 KB Output is correct
29 Correct 54 ms 6140 KB Output is correct
30 Correct 53 ms 6028 KB Output is correct