Language: C++

/*
 * Author:  lee1r
 * Created Time:  2011/8/24 15:42:22
 * File Name: 8.24_G.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#define L(x) ((x)<<1)
#define R(x) ((x)<<1|1)
#define Half(x) ((x)>>1)
#define Lowbit(x) ((x)&(-(x)))
using namespace std;
const int kInf(0x7f7f7f7f);
const double kEps(1e-8);
typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;

bool scanf(int &num)
{
    char in;
    while((in=getchar())!=EOF && (in>'9' || in<'0'));
    if(in==EOF) return false;
    num=in-'0';
    while(in=getchar(),in>='0' && in<='9') num*=10,num+=in-'0';
    return true;
}

int init[7]={};
int dice[50][7]={
{0,0,0,0,0,0},
{6,2,3,5,4,1},
{6,3,5,4,2,1},
{6,4,2,3,5,1},
{1,3,2,4,5,6},
{1,4,5,3,2,6},
{2,1,3,6,4,5},
{1,5,3,2,4,6},
{5,6,3,1,4,2},
{4,2,6,5,1,3},
{2,3,6,4,1,5},
{3,5,6,2,1,4},
{5,4,6,3,1,2},
{1,2,4,5,3,6},
{2,6,4,1,3,5},
{6,5,4,2,3,1},
{5,1,4,6,3,2},
{3,2,1,5,6,4},
{2,4,1,3,6,5},
{4,5,1,2,6,3},
{5,3,1,4,6,2},
{4,1,2,6,5,3},
{3,1,5,6,2,4},
{4,6,5,1,2,3},
{3,6,2,1,5,4}
};

void Left(int *a,int *b)
{
    b[1]=a[1];b[3]=a[3];
    b[0]=a[4];b[4]=a[5];b[5]=a[2];b[2]=a[0];
}

void Front(int *a,int *b)
{
    b[4]=a[4];b[2]=a[2];
    b[0]=a[1];b[1]=a[5];b[5]=a[3];b[3]=a[0];
}

int N,M,r[17][17],x0,y0,x1,y1;
int dist[9999];
bool inq[9999];

int f(int a,int b,int c,int d)
{
    return a*1000+b*100+c*10+d;
}

void SPFA()
{
    int start(f(x0,y0,6,2));
    queue<int> q;
    memset(inq,false,sizeof(inq));
    memset(dist,0x7f,sizeof(dist));
    dist[start]=0;
    q.push(start);
    inq[start]=true;
    while(!q.empty())
    {
        int t(q.front());q.pop();inq[t]=false;
        int d(dist[t]);
        int nowx,nowy,nowa,nowb;
        nowb=t%10;t/=10;
        nowa=t%10;t/=10;
        nowy=t%10;t/=10;
        nowx=t%10;
        int pos;
        for(pos=1;pos<=24;pos++)
            if(dice[pos][0]==nowa && dice[pos][1]==nowb)
                break;
        int news[7];
        if(nowy-1>=0)
        {
            Left(dice[pos],news);
            int tt(f(nowx,nowy-1,news[0],news[1]));
            if(dist[tt]>d+r[nowx][nowy-1]*news[0])
            {
                dist[tt]=d+r[nowx][nowy-1]*news[0];
                if(!inq[tt])
                {
                    q.push(tt);
                    inq[tt]=true;
                }
            }
        }
        if(nowx+1<N)
        {
            Front(dice[pos],news);
            int tt(f(nowx+1,nowy,news[0],news[1]));
            if(dist[tt]>d+r[nowx+1][nowy]*news[0])
            {
                dist[tt]=d+r[nowx+1][nowy]*news[0];
                if(!inq[tt])
                {
                    q.push(tt);
                    inq[tt]=true;
                }
            }
        }
        if(nowx-1>=0)
        {
            int tmp[7];
            Front(dice[pos],news);
            Front(news,tmp);
            Front(tmp,news);
            int tt(f(nowx-1,nowy,news[0],news[1]));
            if(dist[tt]>d+r[nowx-1][nowy]*news[0])
            {
                dist[tt]=d+r[nowx-1][nowy]*news[0];
                if(!inq[tt])
                {
                    q.push(tt);
                    inq[tt]=true;
                }
            }
        }
        if(nowy+1<M)
        {
            int tmp[7];
            Left(dice[pos],news);
            Left(news,tmp);
            Left(tmp,news);
            int tt(f(nowx,nowy+1,news[0],news[1]));
            if(dist[tt]>d+r[nowx][nowy+1]*news[0])
            {
                dist[tt]=d+r[nowx][nowy+1]*news[0];
                if(!inq[tt])
                {
                    q.push(tt);
                    inq[tt]=true;
                }
            }
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("data.in","r",stdin);
    #endif
    
    while(scanf(N) && scanf(M) && (N || M))
    {
        for(int i=0;i<N;i++)
            for(int j=0;j<M;j++)
                scanf(r[i][j]);
        scanf(x0);scanf(y0);
        scanf(x1);scanf(y1);
        //  Input
        
        SPFA();
        
        int ans(kInf);
        for(int i=1;i<=6;i++)
            for(int j=1;j<=6;j++)
                ans=min(ans,dist[f(x1,y1,i,j)]);
        
        printf("%d\n",ans);
    }
    
    return 0;
}

Compiler output:
a.cc:86:22: error: 'int y0' redeclared as different kind of entity
   86 | int N,M,r[17][17],x0,y0,x1,y1;
      |                      ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:6:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:256:1: note: previous declaration 'double y0(double)'
  256 | __MATHCALL (y0,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc:86:28: error: 'int y1' redeclared as different kind of entity
   86 | int N,M,r[17][17],x0,y0,x1,y1;
      |                            ^~
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'void SPFA()':
a.cc:97:20: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   97 |     int start(f(x0,y0,6,2));
      |                    ^~
      |                    |
      |                    double (*)(double) noexcept
a.cc:90:17: note:   initializing argument 2 of 'int f(int, int, int, int)'
   90 | int f(int a,int b,int c,int d)
      |             ~~~~^
a.cc: In function 'int main()':
a.cc:194:25: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
  194 |         scanf(x0);scanf(y0);
      |                         ^~
      |                         |
      |                         double (*)(double) noexcept
a.cc:35:17: note:   initializing argument 1 of 'bool scanf(int&)'
   35 | bool scanf(int &num)
      |            ~~~~~^~~
a.cc:194:25: error: cannot bind rvalue '(int)y0' to 'int&'
  194 |         scanf(x0);scanf(y0);
      |                         ^~
a.cc:195:25: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
  195 |         scanf(x1);scanf(y1);
      |                         ^~
      |                         |
      |                         double (*)(double) noexcept
a.cc:35:17: note:   initializing argument 1 of 'bool scanf(int&)'
   35 | bool scanf(int &num)
      |            ~~~~~^~~
a.cc:195:25: error: cannot bind rvalue '(int)y1' to 'int&'
  195 |         scanf(x1);scanf(y1);
      |                         ^~
a.cc:203:39: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
  203 |                 ans=min(ans,dist[f(x1,y1,i,j)]);
      |                                       ^~
      |                                       |
      |                                       double (*)(double) noexcept
a.cc:90:17: note:   initializing argument 2 of 'int f(int, int, int, int)'
   90 | int f(int a,int b,int c,int d)
      |             ~~~~^