Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int r,c;
- string ss;
- char mat[51][51];
- int go[2501][4];
- int dr[4] = {0,0,1,-1};
- int dc[4] = {-1,1,0,0};
- pair<int,int> next_(int x,int y, int i, int j, char previous)
- {
- if(mat[x][y]!=previous)
- return make_pair(x,y);
- else
- {
- if(x+i>r || y+j>c)
- return make_pair(-1,-1);
- return next_(x+i,y+j,i,j,mat[i][j]);
- }
- }
- void build()
- {
- for(int i=0;i<r;i++)
- for(int j=0;j<c;j++)
- for(int k=0;k<4;k++)
- {
- pair<int,int> x = next_(i+dr[k],j+dc[k],dr[k],dc[k],mat[i][j]);
- go[i*c+r][k] = (x.first==-1)?-1: x.first * r + x.second;
- }
- }
- void read_mat()
- {
- for(int i=0;i<r;i++)
- for(int j=0;j<c;j++)
- cin>>mat[i][j];
- }
- void solve()
- {
- }
- int main()
- {
- while(cin>>r>>c)
- {
- read_mat();
- build();
- cin>>ss;
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement