/** * * * * * * * * * * * * * **\
* *
* Author:Ram Azar Alzaher *
* Coded in: YYYY\M\D HH:MM:SS *
* Lang: C++ *
* *
\** * * * * * * * * * * * * * **/
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define itn int
#define rep(i,x,n) for(int i=(x);i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=(x);i>(n);i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define vi vector< int >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define um(i,j) unordered_map< i , j >
#define s(i) set< i >
#define us(i) unordered_set< i >
#define set set<int>
#define uset unordered_set<int>
#define mp make_pair
#define f first
#define rall(x) x.rbegin(),x.rend()
#define all(x) x.begin(),x.end()
#define so(x) sort(all(s))
#define so(x) sort(all(s))
#define s second
#define sz size()
#define pb push_back
#define test long long t ;cin >> t ;while(t--)
using namespace std;
//*****************************************************VARIABLES***************************************************************\\\\*******************************\\
//*****************************************************************************************************************************\\\\
//***************************************************************************************************************************************
const double pi=2.0*acos(0.0);
const int inf=1LL<<62LL;
const int mod=1e9+7;
int dx[] {1,-1,0,0};
int dy[] {0,0,-1,1};
int max1 = INT_MIN;
int min1 = INT_MAX;
//*****************************************************************************************************************************\\\\
//**************************************************************************************************************************************
//******************************************************************************************************************************\****************
//*****************************************************FUNCTIONS***************************************************************\\\\*******************************\\
//*****************************************************************************************************************************\\\\
//***************************************************************************************************************************************
void setIO(string name = "") {
if(name != ""){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
const int N = 4004 ;
int n , m ;
char a[N][N] ;
int vis[N][N] , dis[N][N];
bool isvalid(int x ,int y ){
if(x >= n || y >= m || y < 0 || x < 0 || vis[x][y]||a[x][y] == '.' )return 0 ;
return 1 ;
}
//*****************************************************************************************************************************\\\\
//**************************************************************************************************************************************
//******************************************************************************************************************************\****************
signed main()
{
fast;
setIO();
cin >> n >> m ;
FOR(i , n )FOR(j , m )cin >> a[i][j] ;
deque<pii> q ;
q.push_back({0 ,0 });
vis[0][0]=0 ;
dis[0][0] = 0 ;
while(q.sz) {
auto &[x , y ] = q.front() ;
q.pop_front() ;
FOR(i , 4){
int nx = dx[i]+x;
int ny = dy[i]+y;
if(isvalid(nx , ny )){
if( a[x][y] == a[nx][ny] ){
q.push_front({nx , ny });
dis[nx][ny] = dis[x][y] + 1;
}else {
q.push_back({nx , ny });
dis[nx][ny] = dis[x][y] ;
}
vis[nx][ny] = 1 ;
}
}
}
cout<<dis[n-1][m-1] << endl ;
return 0 ;
}
/**
input :
output :
*/
Compilation message
tracks.cpp:32: warning: "s" redefined
32 | #define s second
|
tracks.cpp:22: note: this is the location of the previous definition
22 | #define s(i) set< i >
|
tracks.cpp:37:1: warning: multi-line comment [-Wcomment]
37 | //*****************************************************VARIABLES***************************************************************\\\\*******************************\\
| ^
tracks.cpp:47:1: warning: multi-line comment [-Wcomment]
47 | //*****************************************************************************************************************************\\\\
| ^
tracks.cpp:52:1: warning: multi-line comment [-Wcomment]
52 | //*****************************************************FUNCTIONS***************************************************************\\\\*******************************\\
| ^
tracks.cpp:71:1: warning: multi-line comment [-Wcomment]
71 | //*****************************************************************************************************************************\\\\
| ^
tracks.cpp: In function 'int main()':
tracks.cpp:87:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
87 | auto &[x , y ] = q.front() ;
| ^
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen((name+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:59:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen((name+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
17244 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
4 |
Incorrect |
9 ms |
16220 KB |
Output isn't correct |
5 |
Incorrect |
4 ms |
10772 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
8028 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
14684 KB |
Output isn't correct |
13 |
Incorrect |
4 ms |
10840 KB |
Output isn't correct |
14 |
Incorrect |
4 ms |
10840 KB |
Output isn't correct |
15 |
Incorrect |
13 ms |
14684 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
17244 KB |
Output isn't correct |
17 |
Incorrect |
11 ms |
18524 KB |
Output isn't correct |
18 |
Incorrect |
10 ms |
16220 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
48988 KB |
Output isn't correct |
2 |
Incorrect |
54 ms |
37808 KB |
Output isn't correct |
3 |
Incorrect |
142 ms |
18632 KB |
Output isn't correct |
4 |
Incorrect |
107 ms |
86440 KB |
Output isn't correct |
5 |
Incorrect |
197 ms |
114188 KB |
Output isn't correct |
6 |
Runtime error |
1224 ms |
571132 KB |
Execution killed with signal 11 |
7 |
Incorrect |
4 ms |
18524 KB |
Output isn't correct |
8 |
Incorrect |
18 ms |
48988 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
11 |
Incorrect |
18 ms |
50120 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
13 |
Incorrect |
50 ms |
38828 KB |
Output isn't correct |
14 |
Incorrect |
29 ms |
23376 KB |
Output isn't correct |
15 |
Incorrect |
32 ms |
32124 KB |
Output isn't correct |
16 |
Incorrect |
22 ms |
16180 KB |
Output isn't correct |
17 |
Incorrect |
34 ms |
14904 KB |
Output isn't correct |
18 |
Incorrect |
125 ms |
92120 KB |
Output isn't correct |
19 |
Incorrect |
108 ms |
88712 KB |
Output isn't correct |
20 |
Incorrect |
29 ms |
12624 KB |
Output isn't correct |
21 |
Incorrect |
92 ms |
47440 KB |
Output isn't correct |
22 |
Incorrect |
206 ms |
118876 KB |
Output isn't correct |
23 |
Incorrect |
81 ms |
26304 KB |
Output isn't correct |
24 |
Incorrect |
84 ms |
21292 KB |
Output isn't correct |
25 |
Incorrect |
134 ms |
26828 KB |
Output isn't correct |
26 |
Incorrect |
671 ms |
290596 KB |
Output isn't correct |
27 |
Runtime error |
1151 ms |
625420 KB |
Execution killed with signal 11 |
28 |
Runtime error |
1109 ms |
579060 KB |
Execution killed with signal 11 |
29 |
Runtime error |
1102 ms |
570528 KB |
Execution killed with signal 11 |
30 |
Runtime error |
1105 ms |
568040 KB |
Execution killed with signal 11 |
31 |
Incorrect |
532 ms |
210944 KB |
Output isn't correct |
32 |
Incorrect |
796 ms |
313484 KB |
Output isn't correct |