답안 #880341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880341 2023-11-29T07:57:15 Z themaver1cks Tracks in the Snow (BOI13_tracks) C++11
100 / 100
734 ms 223240 KB
/**
。∠(*・ω・)っ  ⌒ 由 ~	(( ,,・з・,, ))
 _Π_____。
/______/~\
| 田田|門|
**/

#include <bits/stdc++.h>

using namespace std;

#define fori(i, l, r) for(int i = l; i < r; ++i)
#define forie(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, l, r) for (int i = l; i > r; --i)
#define forde(i, l, r) for (int i = l; i >= r; --i)
#define int long long
#define i_inf INT_MAX
#define inf LLONG_MAX
#define ii pair<int,int>
#define fi first
#define se second
#define gcd __gcd(x, y)
#define lcm(x,y) x * y/ gcd(x,y)
#define pb push_back
#define eb emplace_back
#define sz size
#define all(x) begin(x), end(x)
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr);
#define el "\n"
#define sp " "
//
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
// var declare
const int maxn = 4e3 + 3;
int n, m;
int ans = 0;
// ds declare
char a[maxn][maxn];
//
bool check(int x, int y)
{
    return (x > 0 && y > 0 && x <= m && y <= n && a[x][y] != '.');
}
//
void bfs0_1()
{
    deque <ii> dq;
    vector <vector<int>> d(m+1, vector<int>(n+1, 0));
    d[1][1] = 1;
    dq.push_front({1, 1});
    while (dq.sz())
    {
        auto [x, y] = dq.front();
        dq.pop_front();
        ans = max(ans, d[x][y]);
        fori(z, 0, 4)
        {
            int x1 = x + dr[z], y1 = y + dc[z];
            if (check(x1, y1) && d[x1][y1] == 0)
            {
                if (a[x][y] == a[x1][y1])
                {
                    d[x1][y1] = d[x][y];
                    dq.push_front({x1, y1});
                }
                else
                {
                    d[x1][y1] = d[x][y] + 1;
                    dq.push_back({x1, y1});
                }
            }
        }
    }
}
//
void solve()
{
    cin >> m >> n;
    forie(i, 1, m)
        forie(j, 1, n) cin >> a[i][j];
    bfs0_1();
    cout << ans;
}
//
void multi_test()
{
	int t;
	cin >> t;
	while (t--) solve();
}
//
int32_t main()
{
	fastio;
	solve();
	return 0;
}

/**
5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
**/

Compilation message

tracks.cpp: In function 'void bfs0_1()':
tracks.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |         auto [x, y] = dq.front();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4956 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 9 ms 4444 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 3 ms 3420 KB Output is correct
11 Correct 2 ms 3164 KB Output is correct
12 Correct 4 ms 3544 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 2 ms 3452 KB Output is correct
15 Correct 9 ms 4980 KB Output is correct
16 Correct 10 ms 4956 KB Output is correct
17 Correct 8 ms 4680 KB Output is correct
18 Correct 7 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15960 KB Output is correct
2 Correct 42 ms 20588 KB Output is correct
3 Correct 277 ms 156932 KB Output is correct
4 Correct 74 ms 41960 KB Output is correct
5 Correct 157 ms 92144 KB Output is correct
6 Correct 734 ms 186576 KB Output is correct
7 Correct 3 ms 16472 KB Output is correct
8 Correct 3 ms 15964 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 3 ms 16220 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 40 ms 20492 KB Output is correct
14 Correct 23 ms 12636 KB Output is correct
15 Correct 19 ms 13364 KB Output is correct
16 Correct 18 ms 8284 KB Output is correct
17 Correct 102 ms 44652 KB Output is correct
18 Correct 87 ms 44116 KB Output is correct
19 Correct 85 ms 41960 KB Output is correct
20 Correct 63 ms 39184 KB Output is correct
21 Correct 163 ms 94800 KB Output is correct
22 Correct 174 ms 92016 KB Output is correct
23 Correct 197 ms 79268 KB Output is correct
24 Correct 168 ms 92972 KB Output is correct
25 Correct 537 ms 156932 KB Output is correct
26 Correct 495 ms 223240 KB Output is correct
27 Correct 593 ms 215372 KB Output is correct
28 Correct 734 ms 186236 KB Output is correct
29 Correct 674 ms 178116 KB Output is correct
30 Correct 663 ms 193296 KB Output is correct
31 Correct 442 ms 106348 KB Output is correct
32 Correct 621 ms 195928 KB Output is correct