UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204840#3629. 路径判断lsr100807ms1460kbC++111.0kb2024-06-10 09:41:122024-06-10 12:02:40

answer

#include <bits/stdc++.h>
using namespace std;

#define QwQ3301AwA return 0
#define ll long long

const int N = 505;
int n;
ll k;
struct Mat {
    bitset <N> f[N];
    Mat operator * (const Mat rhs) const {
        Mat ans;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (f[i][j]) ans.f[i] |= rhs.f[j];
            }
        }
        return ans;
    }
};
string s;
Mat bs, ans;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == '1') bs.f[i][j] = 1;
            else bs.f[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) ans.f[i][i] = 1;
    for (int i = 0; i < 60; i++) {
        if ((k >> i) & 1) ans = ans * bs;
        bs = bs * bs;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << ans.f[i][j];
        }
        cout << '\n';
    }
    QwQ3301AwA;
}

详细

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

Test #1:

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

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: 2ms
memory: 1452kb

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: 1448kb

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: 10ms
memory: 1460kb

input:

100 1000000000000000000
0000000000000000000000000000000000000000000000010000000000000000000000000000...

output:

1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 4ms
memory: 1456kb

input:

100 999999999999999
00000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok 100 lines

Test #6:

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

input:

100 13131313311313313
000000000000000000000000000000000000000000000000000000000000000000000000100000...

output:

1111111111111111111111111111111111111011111111111111001111111011111011111001111111111111111011011101...

result:

ok 100 lines

Test #7:

score: 10
Accepted
time: 229ms
memory: 1460kb

input:

500 1000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1111110111111110111101111111111111111111111110111111111111111111111010111111111101111111111110111111...

result:

ok 500 lines

Test #8:

score: 10
Accepted
time: 183ms
memory: 1460kb

input:

500 999999999999999999
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0000100111010000101110110111010111111000101111101010111011101101111111111111010001101110111001111000...

result:

ok 500 lines

Test #9:

score: 10
Accepted
time: 175ms
memory: 1456kb

input:

500 511541551151515454
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0110110111100011111011110101101110011011101101010111111111111110101101100111001110111111111111111111...

result:

ok 500 lines

Test #10:

score: 10
Accepted
time: 195ms
memory: 1456kb

input:

500 777777777777777777
00000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1011100101111010101001111111111111110101111110111110011101111101011011111111110110010111101111101011...

result:

ok 500 lines

Extra Test:

score: 0
Extra Test Passed