Problem: Example

Input

0 3 1 7 5 9 8 6 4 2
7 0 9 2 1 5 4 8 6 3
4 2 0 6 8 7 1 3 5 9
1 7 5 0 9 8 3 4 2 6
6 1 2 3 0 4 5 9 7 8
3 6 7 4 2 0 9 5 8 1
5 8 6 9 7 2 0 1 3 4
8 9 4 5 3 6 2 0 1 7
9 4 3 8 6 1 7 2 0 5
2 5 8 1 4 3 6 7 9 0


Output

0

Solution (in CPP):

Solution:
#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF 1e18
#define endl '\n'
#define vsort(v) sort(v.begin(),v.end())
int A[11][11],num[10];
int calc_parity()
{
    int i=0,j=num[1];
    for(int k=1;k<=4;k++)
    {
        i=A[i][j];
        j=num[k+1];
    }
    return i;
}
bool calc_error()
{
    int i=0,j=num[1];
    for(int k=1;k<=5;k++)
    {
        i=A[i][j];
        j=num[k+1];
    }
    return i==0;
}
bool generate_error()
{
    int f=0;
    for(int i=1;i<=5;i++)
    {
        for(int j=0;j<=9;j++)
        {
            if(j==num[i])continue;
            int x=num[i];
            num[i]=j;
            if(calc_error())
            {
                return true;
            }
            num[i]=x;
        }
        if(f)break;
    }
   // if(f==0)return false;
     for(int i=1;i<=4;i++)
    {
            if(num[i]==num[i+1])continue;
            swap(num[i],num[i+1]);
            if(calc_error())return true;
            swap(num[i],num[i+1]);
    }
    ///cout<<1111111<<endl;
    return false;
}
int main()
{
    /// ios_base::sync_with_stdio(0);
    /// cin.tie(0);
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
            scani(A[i][j]);
    }
    int ans=0;
    for(int i=0;i<10000;i++)
    {
        int x=i,j=4;
        while(x>0)
        {
            num[j--]=x%10;
            x/=10;
        }
        while(j!=0)
        {
            num[j--]=0;
        }
        num[5]=calc_parity();
        if(generate_error())ans++;
    }
    printf("%d\n",ans);
    return 0;
}