Submission #1305394

#TimeUsernameProblemLanguageResultExecution timeMemory
1305394nikaa123Tracks in the Snow (BOI13_tracks)C++20
0 / 100
399 ms141656 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pp pop_back
#define endl '\n'
#define ff first
#define ss second
#define stop exit(0)
#define sz(x) (int)x.size()
#define pause system("pause")
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << "-" << x << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef char chr;
typedef string str;
typedef long long ll;
typedef vector<int> vii;
typedef pair<int, int> pii;
 
const long long INF = LLONG_MAX;
const int inf = INT_MAX;
const int mod = 998244353;
const int MOD = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const double PI = 2 * acos(0.0);
 
const int N = 4e3+5;
 
int h,w;
string bd[N];
int cntr;
int cntc;
int fix[N][N];

bool inbound(int x, int y) {
    return (1 <= x && x <= h && 1 <= y && y <= w);
}

inline void test_case() {
    
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        cin >> bd[i];
        bd[i] = " " + bd[i];
        for (int j = 1; j <= w; j++) {
            if (bd[i][j] == '.') continue;
            if (bd[i][j] == 'R') cntr=1; else cntc=1;
        }
    }
    if (cntr+cntc<1) {
        cout << cntr+cntc << endl;
    }
    char c = bd[1][1];
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (fix[i][j]) continue;
            if (bd[i][j]!=c) continue;
            ans++;
            queue<pii> q;
            q.push({i,j});
            fix[i][j] = 1;
            while (!q.empty()) {
                auto [x,y] = q.front();
                q.pop();
                for (int i = 0; i < 4; i++) {
                    int nx = x + dx[i];
                    int ny = y + dy[i];
                    if (!inbound(nx,ny)) continue;
                    if (fix[nx][ny]) continue;
                    if (bd[nx][ny] != c) continue;
                    fix[nx][ny] = 1;
                    q.push({nx,ny});
                }
            }
        }
    }
    cout << min(ans,2LL)+1 << endl;
    
    
    
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int T = 1;
    // cin >> T;
    while (T--) test_case();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...