Submission #73323926


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, s, e) for (ll i = (ll)(s); i < (ll)(e); ++i)
#define rrep(i, s ,e) for (ll i = (ll)(s); i > (ll)(e); --i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 61;
const ll MOD = 998244353;
//const ll MOD = 1000000007;

vector<vector<ll>> f(vector<vector<ll>> a,vector<vector<ll>> b,ll mod){
    vector<vector<ll>> res(a.size(),vector<ll>(b[0].size(),INF));
    rep(i,0,res.size()){
        rep(j,0,res[0].size()){
            rep(k,0,b.size()){
                res[i][j] = min(res[i][j],a[i][k]+b[k][j]);
                //res[i][j] %= mod;
            }
        }
    }
    return res;
}
vector<vector<ll>> matrixpow(vector<vector<ll>> a,ll n,ll mod){
    vector<vector<ll>> res(a.size(),vector<ll>(a.size(),INF));
    rep(i,0,a.size())res[i][i] = 0;
    while(n > 0){
        if(n&1) res = f(res,a,mod);
        a = f(a,a,mod);
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);cout.tie(0);
    ios_base::sync_with_stdio(false);

    ll n,k;cin >> n >> k;
    vector<vector<ll>> c(n,vector<ll>(n));
    rep(i,0,n)rep(j,0,n)cin >> c[i][j];
    auto res = matrixpow(c,k,MOD);
    rep(i,0,n)cout << res[i][i] << endl;
}

Submission Info

Submission Time
Task F - Exactly K Steps 2
User KH8047
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1232 Byte
Status AC
Exec Time 30 ms
Memory 4128 KiB

Compile Error

./Main.cpp: In function 'std::vector<std::vector<long long int> > f(std::vector<std::vector<long long int> >, std::vector<std::vector<long long int> >, ll)':
./Main.cpp:10:67: warning: unused parameter 'mod' [-Wunused-parameter]
   10 | vector<vector<ll>> f(vector<vector<ll>> a,vector<vector<ll>> b,ll mod){
      |                                                                ~~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 43
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3608 KiB
00_sample_01.txt AC 1 ms 3576 KiB
00_sample_02.txt AC 1 ms 3556 KiB
01_random_03.txt AC 29 ms 3928 KiB
01_random_04.txt AC 25 ms 4084 KiB
01_random_05.txt AC 29 ms 4128 KiB
01_random_06.txt AC 26 ms 4068 KiB
01_random_07.txt AC 28 ms 4100 KiB
01_random_08.txt AC 23 ms 4088 KiB
01_random_09.txt AC 30 ms 4116 KiB
01_random_10.txt AC 28 ms 4120 KiB
01_random_11.txt AC 26 ms 3972 KiB
01_random_12.txt AC 26 ms 4068 KiB
01_random_13.txt AC 29 ms 4064 KiB
01_random_14.txt AC 28 ms 4068 KiB
01_random_15.txt AC 26 ms 4064 KiB
01_random_16.txt AC 22 ms 4068 KiB
01_random_17.txt AC 1 ms 3704 KiB
01_random_18.txt AC 24 ms 3924 KiB
01_random_19.txt AC 1 ms 3556 KiB
01_random_20.txt AC 11 ms 3668 KiB
01_random_21.txt AC 2 ms 3704 KiB
01_random_22.txt AC 1 ms 3576 KiB
01_random_23.txt AC 9 ms 3812 KiB
01_random_24.txt AC 1 ms 3616 KiB
01_random_25.txt AC 19 ms 3972 KiB
01_random_26.txt AC 3 ms 3588 KiB
01_random_27.txt AC 3 ms 3544 KiB
01_random_28.txt AC 18 ms 3960 KiB
01_random_29.txt AC 22 ms 3924 KiB
01_random_30.txt AC 11 ms 3872 KiB
01_random_31.txt AC 16 ms 3940 KiB
01_random_32.txt AC 5 ms 3672 KiB
01_random_33.txt AC 2 ms 3684 KiB
01_random_34.txt AC 1 ms 3552 KiB
01_random_35.txt AC 1 ms 3556 KiB
01_random_36.txt AC 2 ms 3588 KiB
01_random_37.txt AC 3 ms 3544 KiB
01_random_38.txt AC 30 ms 4064 KiB
01_random_39.txt AC 1 ms 3416 KiB
01_random_40.txt AC 1 ms 3588 KiB
01_random_41.txt AC 1 ms 3436 KiB
01_random_42.txt AC 27 ms 4068 KiB