You Are Given a Decimal String..(最短路,思维)

Suppose you have a special xx-yy-counter. This counter can store some value as a decimal number; at first, the counter has value 00.

The counter performs the following algorithm: it prints its lowest digit and, after that, adds either xx or yy to its value. So all sequences this counter generates are starting from 00. For example, a 44-22-counter can act as follows:

  1. it prints 00, and adds 44 to its value, so the current value is 44, and the output is 00;
  2. it prints 44, and adds 44 to its value, so the current value is 88, and the output is 0404;
  3. it prints 88, and adds 44 to its value, so the current value is 1212, and the output is 048048;
  4. it prints 22, and adds 22 to its value, so the current value is 1414, and the output is 04820482;
  5. it prints 44, and adds 44 to its value, so the current value is 1818, and the output is 0482404824.

This is only one of the possible outputs; for example, the same counter could generate 02468024680240246802468024 as the output, if we chose to add 22 during each step.

You wrote down a printed sequence from one of such xx-yy-counters. But the sequence was corrupted and several elements from the sequence could be erased.

Now you'd like to recover data you've lost, but you don't even know the type of the counter you used. You have a decimal string ss — the remaining data of the sequence.

For all 0≤x,y<100≤x,y<10, calculate the minimum number of digits you have to insert in the string ss to make it a possible output of the xx-yy-counter. Note that you can't change the order of digits in string ss or erase any of them; only insertions are allowed.

Input

The first line contains a single string ss (1≤|s|≤2⋅1061≤|s|≤2⋅106, si∈{0−9}si∈{0−9}) — the remaining data you have. It's guaranteed that s1=0s1=0.

Output

Print a 10×1010×10 matrix, where the jj-th integer (00-indexed) on the ii-th line (00-indexed too) is equal to the minimum number of digits you have to insert in the string ss to make it a possible output of the ii-jj-counter, or −1−1 if there is no way to do so.

Example

input

Copy

0840

output

Copy

-1 17 7 7 7 -1 2 17 2 7 
17 17 7 5 5 5 2 7 2 7 
7 7 7 4 3 7 1 7 2 5 
7 5 4 7 3 3 2 5 2 3 
7 5 3 3 7 7 1 7 2 7 
-1 5 7 3 7 -1 2 9 2 7 
2 2 1 2 1 2 2 2 0 1 
17 7 7 5 7 9 2 17 2 3 
2 2 2 2 2 2 0 2 2 2 
7 7 5 3 7 7 1 3 2 7 

Note

Let's take, for example, 44-33-counter. One of the possible outcomes the counter could print is 0(4)8(1)4(7)00(4)8(1)4(7)0 (lost elements are in the brackets).

One of the possible outcomes a 22-33-counter could print is 0(35)8(1)4(7)00(35)8(1)4(7)0.

The 66-88-counter could print exactly the string 08400840.

思路:

1,问题在于如何才能想起这个floy,

要求只能插数,距离是i或者j,问题最小插入的数的个数=》距离相当于floy初始化里的内容,最小个数相当于最短路,(a直接到b,还是经过k过渡),结合数据范围即可

参看floy

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector<int>
const int maxj=2e6+1000,mod=998244353,inf=0x7f7f7f7f7f7f7f;
int a[20][20];
string s;
int b[120][120];
int ask(int x,int y){//注重学最短路floy
    memset(b,mod,sizeof(b));
    for(int i=0;i<10;++i){
        b[i][(i+x)%10]=b[i][(i+y)%10]=1;
    }//初始化
    for(int k=0;k<10;++k){
        for(int i=0;i<10;++i){
            for(int j=0;j<10;++j){
                b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
            }
        }//floy的板子,
    }int ans=0;
    for(int i=0;i<s.size()-1;++i){
        int aa=s[i]-'0',bb=s[i+1]-'0';
        if(b[aa][bb]>=mod)return -1;
        ans+=b[aa][bb]-1;//a到b一步到位时,不需插入
    }return ans;
}
void solve(){
    //暴力
    cin>>s;
    for(int i=0;i<10;++i){
        for(int j=0;j<10;++j){
            cout<<ask(i,j)<<' ';//暴力即可
        }cout<<'\n';
    }
}
signed main(){
    ios::sync_with_stdio(0);//能不用c语言的输入输出,尽量不要用
    cin.tie(0);
    cout.tie(0);
    int t;
    // cin>>t;
    t=1;
    while(t--)solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值