Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<iomanip>
- using namespace std;
- #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
- int main() {///main function starts here
- fastio;
- int n,x;
- while(!(cin>>n).eof()){
- int a,b;
- int steps,min_steps;
- bool found=false,bfound=false;
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- scanf("%1d",&x);
- if(x==1 && !found){
- a=i;
- b=j;
- found=true;
- }
- else if(x==3 && !bfound){
- bfound=true;
- min_steps=abs(a-i)+abs(b-j);
- break;
- }
- else if(x==3 && bfound){
- steps=abs(a-i)+abs(b-j);
- if(steps<min_steps){
- min_steps=steps;
- break;
- }
- }
- if(j>=min_steps && bfound)break;
- }
- if(i>=min_steps)break;
- }
- cout<<min_steps<<endl;
- }
- return 0;
- }///main function ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement