답안 #890537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890537 2023-12-21T12:20:03 Z thunopro Tracks in the Snow (BOI13_tracks) C++14
100 / 100
644 ms 128612 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 4009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1 
#define right id<<1|1
#define re exit(0);
#define _lower(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()+1

const int mod = 1e9+7 ; 
const int INF = 1e9 ;
const int LOG = 18 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ;
typedef vector<ll> vl ;  
typedef pair<ll,ll> pll ; 
typedef vector<pll> vll ; 

void add ( int&a , int b ) { if ((a+=b) > mod ) a -= mod ; } 
void sub ( int&a , int b ) { if ((a-=b) < 0 ) a += mod ; } 
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}

void rf ( ) 
{
	freopen ("bai1.inp","r",stdin) ; 
//	freopen ("bai1.out","w",stdout) ;
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow ( a , n / 2 ) ; 
	if ( n % 2 ) return ( 1ll * res * res % mod * a % mod ) ; 
	else return ( 1ll * res * res % mod ) ; 
}

int n , m ; 
char a [maxn][maxn] ; 

int dx [] = {0,0,-1,1} ; 
int dy [] = {1,-1,0,0} ;
bool inside ( int x , int y ) 
{
	return (x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]!='.') ; 
}

int d [maxn][maxn] ; 
int main ( ) 
{
	ios_base :: sync_with_stdio (0) ; 
	cin.tie(0) ; cout.tie(0) ;
//	rf () ; 
	cin >> n >> m ; 
	for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= m ; j ++ ) cin >> a [i][j] ; 
	
	deque <pii> q ; 
	memset ( d , 0x3f , sizeof d ) ; 
	d [1][1] = 1 ; 
	q . pb ({1,1}) ; 
	while (!q.empty()) 
	{
		int u = q.front().fi , v = q.front().se ; 
		q.pop_front() ; 
		for ( int i = 0 ; i < 4 ; i ++ ) 
		{
			int x = u + dx [i] , y = v + dy [i] ; 
			if ( inside (x,y) ) 
			{
				if ( a [x][y] == a [u][v] && d[x][y]>d[u][v] ) q.push_front({x,y}) , d [x][y] = d [u][v] ; 
				else if ( d [x][y] > d [u][v] + 1 ) 
				{
					q . pb ({x,y}) ; 
					d [x][y] = d [u][v] + 1 ; 
				}
			}
		}
	}
	int res = 0 ; 
	for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= m ; j ++ ) 
	{
		if ( a[i][j] == '.' ) continue ; 
		chkmax (res,d[i][j]) ; 
	}
	cout << res ; 
}




//-std=c++11

Compilation message

tracks.cpp: In function 'void rf()':
tracks.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 66364 KB Output is correct
2 Correct 7 ms 64104 KB Output is correct
3 Correct 8 ms 64092 KB Output is correct
4 Correct 13 ms 66396 KB Output is correct
5 Correct 10 ms 66272 KB Output is correct
6 Correct 7 ms 64092 KB Output is correct
7 Correct 8 ms 64092 KB Output is correct
8 Correct 8 ms 64092 KB Output is correct
9 Correct 8 ms 64092 KB Output is correct
10 Correct 9 ms 66140 KB Output is correct
11 Correct 10 ms 64092 KB Output is correct
12 Correct 12 ms 66336 KB Output is correct
13 Correct 9 ms 66136 KB Output is correct
14 Correct 9 ms 66136 KB Output is correct
15 Correct 18 ms 66140 KB Output is correct
16 Correct 22 ms 66368 KB Output is correct
17 Correct 16 ms 66140 KB Output is correct
18 Correct 13 ms 66512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 78428 KB Output is correct
2 Correct 47 ms 68184 KB Output is correct
3 Correct 266 ms 79044 KB Output is correct
4 Correct 73 ms 72452 KB Output is correct
5 Correct 162 ms 76376 KB Output is correct
6 Correct 630 ms 92488 KB Output is correct
7 Correct 11 ms 78936 KB Output is correct
8 Correct 10 ms 78588 KB Output is correct
9 Correct 10 ms 64156 KB Output is correct
10 Correct 8 ms 64144 KB Output is correct
11 Correct 10 ms 78684 KB Output is correct
12 Correct 8 ms 64344 KB Output is correct
13 Correct 50 ms 68316 KB Output is correct
14 Correct 32 ms 68184 KB Output is correct
15 Correct 27 ms 68180 KB Output is correct
16 Correct 28 ms 66140 KB Output is correct
17 Correct 115 ms 72276 KB Output is correct
18 Correct 80 ms 72388 KB Output is correct
19 Correct 73 ms 72272 KB Output is correct
20 Correct 68 ms 70228 KB Output is correct
21 Correct 165 ms 76372 KB Output is correct
22 Correct 164 ms 76504 KB Output is correct
23 Correct 206 ms 74324 KB Output is correct
24 Correct 145 ms 76368 KB Output is correct
25 Correct 385 ms 79324 KB Output is correct
26 Correct 392 ms 128612 KB Output is correct
27 Correct 486 ms 100684 KB Output is correct
28 Correct 629 ms 92736 KB Output is correct
29 Correct 644 ms 89928 KB Output is correct
30 Correct 572 ms 94680 KB Output is correct
31 Correct 523 ms 77008 KB Output is correct
32 Correct 449 ms 95240 KB Output is correct