UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204830#3629. 路径判断drdilyor100484ms1404kbC++906b2024-06-10 09:20:522024-06-10 12:00:46

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
const int mod=1e9+7;
#define Matrix vector<bitset<500> >
Matrix mul(Matrix a,Matrix b){
    Matrix res(n);
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(a[i][k]){
                res[i]|=b[k];
            }
        }
    }
    return res;
}
Matrix qkp(Matrix a,int k){
    Matrix res(n);
    for(int i=0;i<n;i++){
        res[i][i]=1;
    }
    while(k){
        if(k&1)res=mul(res,a);
        k/=2;
        a=mul(a,a);
    }
    return res;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>k;
    Matrix a(n);
    for(int i=0;i<n;i++){
        string s;cin>>s;
        for(int j=0;j<n;j++)a[i][j]=s[j]-'0';
    }
    a=qkp(a,k);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cout<<(a[i][j]);
        cout<<"\n";
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

10 4
0001000000
0001001010
0000000000
0100000100
0010001010
0000000001
0000100010
1010000000
0010000...

output:

0111100110
0111100110
0000000000
1111001110
0010100010
0010011010
0010001010
1011001010
0000000000
0...

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

10 5
0100000010
0010010000
0001000000
1000000000
0000010000
0000101000
0010000010
0000110000
0000000...

output:

0101101011
1010011011
0001101000
1010010010
1010011010
0111101011
0011010001
1011111011
1000001000
0...

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

9 5
000000000
000001001
100010000
100010001
000100000
000100001
000000000
000001101
010000000

output:

000000000
110111001
100011001
110011001
010100001
110111001
000000000
110111001
010101001

result:

ok 9 lines

Test #4:

score: 10
Accepted
time: 3ms
memory: 1312kb

input:

100 1000000000000000000
0000000000000000000000000000000000000000000000010000000000000000000000000000...

output:

1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 9ms
memory: 1308kb

input:

100 999999999999999
00000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok 100 lines

Test #6:

score: 10
Accepted
time: 5ms
memory: 1308kb

input:

100 13131313311313313
000000000000000000000000000000000000000000000000000000000000000000000000100000...

output:

1111111111111111111111111111111111111011111111111111001111111011111011111001111111111111111011011101...

result:

ok 100 lines

Test #7:

score: 10
Accepted
time: 123ms
memory: 1400kb

input:

500 1000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1111110111111110111101111111111111111111111110111111111111111111111010111111111101111111111110111111...

result:

ok 500 lines

Test #8:

score: 10
Accepted
time: 119ms
memory: 1404kb

input:

500 999999999999999999
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0000100111010000101110110111010111111000101111101010111011101101111111111111010001101110111001111000...

result:

ok 500 lines

Test #9:

score: 10
Accepted
time: 109ms
memory: 1404kb

input:

500 511541551151515454
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0110110111100011111011110101101110011011101101010111111111111110101101100111001110111111111111111111...

result:

ok 500 lines

Test #10:

score: 10
Accepted
time: 116ms
memory: 1400kb

input:

500 777777777777777777
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1011100101111010101001111111111111110101111110111110011101111101011011111111110110010111101111101011...

result:

ok 500 lines

Extra Test:

score: 0
Extra Test Passed