// [ الأحزاب: 56] ﴿ إِنَّ اللَّهَ وَمَلَائِكَتَهُ يُصَلُّونَ عَلَى النَّبِيِّ ۚ يَا أَيُّهَا الَّذِينَ آمَنُوا صَلُّوا عَلَيْهِ وَسَلِّمُوا تَسْلِيمًا﴾
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <deque>
#include <iomanip>
#define mem(a, b) memset(a, b, sizeof a);
#define db(x) cout << #x << ": " << (x) << "\n";
#define coutfloat(n,d) cout << fixed << setprecision(d) << n << endl //#include <iomanip>
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pss pair<string , string>
#define fv(vec) for(auto &v : vec)
#define cinv(v,n) vector<int>v(n);for(int i = 0 ; i <n ; i++)cin>>v[i];
#define cinvll(v,n) vector<ll>v(n);for(ll i = 0 ; i <n ; i++)cin>>v[i];
#define fi(n) for(int i = 0 ; i < n ; i++)
#define fj(n) for(int j = 0 ; j < n ; j++)
#define feq(n) for(int eq = 0 ; eq <= n ; eq++)
#define pb push_back
#define mp make_pair
#define ll long long
#define ini in<int>()
#define inl in<ll>()
#define inc in<char>()
#define inb in<bool>()
#define ins in<string>()
#define test int T;cin>>T;while(T--)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define LAITH ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define file freopen("knapsack.in", "r", stdin);freopen("knapsack.out", "w", stdout);
using namespace std;
template <typename T>
T in() { T x; cin >> x; return x; }
int meadow[4004][4004];
string snow[4004];
int n, m , ans = 1,dx[] = {1,-1,0,0},dy[] = {0,0,1,-1};
bool chk(int x, int y){
return (x >= 0 && x <n && y >= 0 && y < m && snow[x][y] != '.');
}
void BFS(){
deque<pii> q;
q.push_front({0,0});
meadow[0][0] = 1;
while(q.size()){
pii point = q.front();
q.pop_front();
ans = max(ans, meadow[point.first][point.second]);
fi(4){
int x = point.first + dx[i], y = point.second + dy[i];
if(chk(x, y) && !meadow[x][y])
snow[x][y] == snow[point.first][point.second] ?
(meadow[x][y] = meadow[point.first][point.second],q.push_front({x,y})):
(meadow[x][y] = meadow[point.first][point.second] + 1,q.push_back({x,y}));
}
}
}
void solve(){
n = ini , m = ini;
fi(n)cin >> snow[i];
BFS();
cout <<ans;
}
int main() {
LAITH;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
3932 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
5 ms |
3672 KB |
Output is correct |
5 |
Correct |
2 ms |
2140 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
1712 KB |
Output is correct |
11 |
Correct |
2 ms |
1624 KB |
Output is correct |
12 |
Correct |
3 ms |
2140 KB |
Output is correct |
13 |
Correct |
3 ms |
2140 KB |
Output is correct |
14 |
Correct |
3 ms |
1956 KB |
Output is correct |
15 |
Correct |
8 ms |
3676 KB |
Output is correct |
16 |
Correct |
11 ms |
3932 KB |
Output is correct |
17 |
Correct |
7 ms |
3676 KB |
Output is correct |
18 |
Correct |
5 ms |
3672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15964 KB |
Output is correct |
2 |
Correct |
27 ms |
11500 KB |
Output is correct |
3 |
Correct |
133 ms |
68192 KB |
Output is correct |
4 |
Correct |
50 ms |
27760 KB |
Output is correct |
5 |
Correct |
75 ms |
47292 KB |
Output is correct |
6 |
Correct |
431 ms |
102564 KB |
Output is correct |
7 |
Correct |
8 ms |
16728 KB |
Output is correct |
8 |
Correct |
6 ms |
16100 KB |
Output is correct |
9 |
Correct |
1 ms |
780 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
6 ms |
16476 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
24 ms |
11352 KB |
Output is correct |
14 |
Correct |
15 ms |
8028 KB |
Output is correct |
15 |
Correct |
11 ms |
10120 KB |
Output is correct |
16 |
Correct |
16 ms |
4956 KB |
Output is correct |
17 |
Correct |
64 ms |
23648 KB |
Output is correct |
18 |
Correct |
46 ms |
30560 KB |
Output is correct |
19 |
Correct |
42 ms |
27816 KB |
Output is correct |
20 |
Correct |
34 ms |
21072 KB |
Output is correct |
21 |
Correct |
87 ms |
46624 KB |
Output is correct |
22 |
Correct |
75 ms |
47304 KB |
Output is correct |
23 |
Correct |
132 ms |
38996 KB |
Output is correct |
24 |
Correct |
81 ms |
43232 KB |
Output is correct |
25 |
Correct |
230 ms |
88852 KB |
Output is correct |
26 |
Correct |
282 ms |
124908 KB |
Output is correct |
27 |
Correct |
366 ms |
115704 KB |
Output is correct |
28 |
Correct |
455 ms |
102636 KB |
Output is correct |
29 |
Correct |
447 ms |
100844 KB |
Output is correct |
30 |
Correct |
424 ms |
105176 KB |
Output is correct |
31 |
Correct |
300 ms |
67412 KB |
Output is correct |
32 |
Correct |
301 ms |
100848 KB |
Output is correct |