abc079d <Floyed>

D - Wall

// https://atcoder.jp/contests/abc079/tasks/abc079_d
// <Floyed>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
using LL = long long;
int c[10][10];

void solv()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i <= 9; i ++)
        for (int j = 0; j <= 9; j ++)
            cin >> c[i][j];

    for (int k = 0; k < 10; k ++)
        for (int i = 0; i < 10; i ++)
            for (int j = 0; j < 10; j ++)
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    int ans = 0;
    for (int i = 1; i <= h; i ++)
        for (int j = 1; j <= w; j ++)
        {
            int t;
            cin >> t;
            if (t >= 0) ans += c[t][1];
        }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
	// cin >> T;
    while (T --)
    {
        solv();
    }
    return 0;
}

posted @ 2023-07-11 16:16  O2iginal  阅读(15)  评论(0)    收藏  举报