답안 #338585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338585 2020-12-23T13:09:18 Z aditi17goel Tracks in the Snow (BOI13_tracks) C++14
100 / 100
917 ms 225304 KB
#include <bits/stdc++.h>
using namespace std;
const int mod =  1000000007;
const int LIM = 100005;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define all(a) a.begin() , a.end()
#define pii pair<int,int>
#define vi vector<int>
#define endl '\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
int power(int x, int n, int m=mod){
    int res = 1;
    while(n){
          if(n&1){
                res = res * x % m;
          }
          x = x * x % m;
          n>>=1;
    }
    return (res%m);
}
/*bool prime[1000006];
void sieve(int n)
{
      memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);
      for (int p = 2; p <= rootn; p++)
            if(prime[p] == true)
                  for(int i = p*p; i <= n; i += p)
                        prime[i] = false;
      prime[1] = 0;

}*/
/*
int fac[300005];
int ncr(int n,int r)
{
      return fac[n]*((power(fac[n-r], mod-2)*power(fac[r], mod-2))%mod)%mod;
}
*/
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};

int n, m, depth[4000][4000], ans = 1;

bool inside(int x, int y, char c) {
    return (x > -1 && x < n && y > -1 && y < m && c != '.');
}
int32_t main()
{
  IOS;
  int tt=1,x,k,y,z,i,j;
  //freopen("checklist.in","r",stdin);
 // freopen("checklist.out","w",stdout);
  //cin>>tt;
  while(tt--){
    cin>>n>>m;
    char a[n+2][m+2];
    for(int i=0; i<n; i++){
      for(int j=0; j<m; j++)
      cin>>a[i][j];
    }
    deque<pair<int, int>> q;
    q.push_back({0, 0});
    depth[0][0] = 1;

    while (q.size()) {
        pair<int, int> c = q.front();
        q.pop_front();
        //cout<<depth[c.first][c.second];
        ans = max(ans, depth[c.first][c.second]);

        for (int i = 0; i < 4; i++) {
            int x = c.first + dx[i], y = c.second + dy[i];
            if (inside(x, y, a[x][y]) && depth[x][y] == 0) {
                if (a[x][y] == a[c.first][c.second]) {
                    depth[x][y] = depth[c.first][c.second];
                    q.push_front({x, y});
                } else {
                    depth[x][y] = depth[c.first][c.second] + 1;
                    q.push_back({x, y});
                }
            }
        }
    }

    cout << ans;
    }
}

Compilation message

tracks.cpp: In function 'int32_t main()':
tracks.cpp:56:12: warning: unused variable 'x' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |            ^
tracks.cpp:56:14: warning: unused variable 'k' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |              ^
tracks.cpp:56:16: warning: unused variable 'y' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |                ^
tracks.cpp:56:18: warning: unused variable 'z' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |                  ^
tracks.cpp:56:20: warning: unused variable 'i' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |                    ^
tracks.cpp:56:22: warning: unused variable 'j' [-Wunused-variable]
   56 |   int tt=1,x,k,y,z,i,j;
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4716 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 10 ms 4204 KB Output is correct
5 Correct 5 ms 2156 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 4 ms 1772 KB Output is correct
11 Correct 3 ms 1644 KB Output is correct
12 Correct 8 ms 2412 KB Output is correct
13 Correct 4 ms 2156 KB Output is correct
14 Correct 5 ms 2156 KB Output is correct
15 Correct 16 ms 4460 KB Output is correct
16 Correct 16 ms 4716 KB Output is correct
17 Correct 13 ms 4588 KB Output is correct
18 Correct 10 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 15980 KB Output is correct
2 Correct 65 ms 14956 KB Output is correct
3 Correct 414 ms 78700 KB Output is correct
4 Correct 125 ms 42092 KB Output is correct
5 Correct 275 ms 61804 KB Output is correct
6 Correct 917 ms 171356 KB Output is correct
7 Correct 13 ms 16620 KB Output is correct
8 Correct 12 ms 16000 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 13 ms 16364 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 62 ms 14956 KB Output is correct
14 Correct 37 ms 9836 KB Output is correct
15 Correct 38 ms 14060 KB Output is correct
16 Correct 36 ms 6380 KB Output is correct
17 Correct 162 ms 31468 KB Output is correct
18 Correct 149 ms 46252 KB Output is correct
19 Correct 134 ms 42092 KB Output is correct
20 Correct 97 ms 26604 KB Output is correct
21 Correct 244 ms 53868 KB Output is correct
22 Correct 276 ms 61932 KB Output is correct
23 Correct 313 ms 50972 KB Output is correct
24 Correct 242 ms 52588 KB Output is correct
25 Correct 734 ms 144196 KB Output is correct
26 Correct 607 ms 225304 KB Output is correct
27 Correct 767 ms 197472 KB Output is correct
28 Correct 909 ms 171428 KB Output is correct
29 Correct 902 ms 168252 KB Output is correct
30 Correct 844 ms 177136 KB Output is correct
31 Correct 752 ms 107236 KB Output is correct
32 Correct 695 ms 168956 KB Output is correct