답안 #856725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856725 2023-10-04T11:58:06 Z Haidara314 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
413 ms 133980 KB
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define mid l+(r-l)/2
#define ya cout<<"YES"<<endl;
#define na cout<<"NO"<<endl;
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define pp pop_back();
//rotate(vec.begin(), vec.begin() + k, vec.end());
//set<int> S(all(a));
/*if (S.count(key)) {
    // ...
}*/
/*if (binary_search(all(vec), key)) {
    // ...
}*/
//int pos = partition_point(all(vec), p) - vec.begin();
//Print a binary representation of a number cout << bitset<20>(n) << "\n";
int nxt() {
    int x;
    cin >> x;
    return x;
}
long long lcm(long long x,long long y)
{
    return (x*y)/__gcd(x,y);
}
int M=1000000007;
ll fp(ll x,ll y)
{
    if(y==0)
        return 1;
    ll m=fp(x,y/2);
    m*=m;
    m%=M;
    if(y%2==1)
        m*=x;
    m%=M;
    return m;
}
int dx[4]{1, -1, 0, 0},dy[4]{0, 0, 1, -1};
char a[4005][4005];
int depth[4005][4005];
int ans=0;
int n,m;
void bfs(int i,int j)
{
    deque<pair<int,int>>q;
    depth[i][j]=1;
    q.push_back({i,j});
    while(!q.empty())
    {
        int x=q.front().F,y=q.front().S;
        q.pop_front();
        ans=max(ans,depth[x][y]);
        for(int g=0;g<4;g++)
        {
            int l=x+dx[g],r=y+dy[g];
            if(l>=n||l<0||r>=m||r<0)
                continue;
            if(a[l][r]=='.')
                continue;
            if(!depth[l][r])
            {
                int f=0;
                if(a[l][r]!=a[x][y])
                f=1;
                depth[l][r]=depth[x][y]+f;
            if(f)
            q.push_back({l,r});
            else
            q.push_front({l,r});
            }
        }

    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(int j=0;j<m;j++)
            a[i][j]=s[j];
    }
    bfs(0,0);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7516 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 5 ms 7412 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 3676 KB Output is correct
11 Correct 3 ms 3724 KB Output is correct
12 Correct 5 ms 6136 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 7 ms 7544 KB Output is correct
16 Correct 9 ms 7516 KB Output is correct
17 Correct 6 ms 7516 KB Output is correct
18 Correct 5 ms 7256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 32348 KB Output is correct
2 Correct 27 ms 16468 KB Output is correct
3 Correct 132 ms 73964 KB Output is correct
4 Correct 41 ms 35576 KB Output is correct
5 Correct 109 ms 56164 KB Output is correct
6 Correct 390 ms 108212 KB Output is correct
7 Correct 9 ms 33112 KB Output is correct
8 Correct 9 ms 32348 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2524 KB Output is correct
11 Correct 9 ms 32800 KB Output is correct
12 Correct 1 ms 3164 KB Output is correct
13 Correct 26 ms 16344 KB Output is correct
14 Correct 18 ms 13148 KB Output is correct
15 Correct 12 ms 15448 KB Output is correct
16 Correct 13 ms 8276 KB Output is correct
17 Correct 62 ms 31056 KB Output is correct
18 Correct 45 ms 38228 KB Output is correct
19 Correct 41 ms 35744 KB Output is correct
20 Correct 35 ms 27224 KB Output is correct
21 Correct 80 ms 54888 KB Output is correct
22 Correct 109 ms 56148 KB Output is correct
23 Correct 129 ms 46456 KB Output is correct
24 Correct 83 ms 52064 KB Output is correct
25 Correct 266 ms 94548 KB Output is correct
26 Correct 231 ms 133980 KB Output is correct
27 Correct 301 ms 121088 KB Output is correct
28 Correct 409 ms 108048 KB Output is correct
29 Correct 413 ms 106588 KB Output is correct
30 Correct 366 ms 111504 KB Output is correct
31 Correct 327 ms 75464 KB Output is correct
32 Correct 292 ms 106396 KB Output is correct