제출 #1120547

#제출 시각아이디문제언어결과실행 시간메모리
1120547AtabayRajabliPalindrome-Free Numbers (BOI13_numbers)C++17
0 / 100
1094 ms85184 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() using namespace std; const int sz = 4e3 + 5; int n, m, used[sz][sz]; char c[sz][sz]; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; signed 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++) cin >> c[i][j]; int ans = 0; bool cur = 0; queue<array<int, 2>> q[2]; q[cur].push({0, 0}); used[0][0] = 1; while(!q[cur].empty()) { ans++; assert(ans < n * m); while(!q[cur].empty()) { int x = q[cur].front()[0], y = q[cur].front()[1]; q[cur].pop(); for(int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || n <= nx || ny < 0 || m <= ny || used[nx][ny] || c[nx][ny] == '.') continue; if(c[nx][ny] == c[x][y]) q[cur].push({nx, ny}); else q[(cur ^ 1)].push({nx, ny}); used[nx][ny] = 1; } } cur ^= 1; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...