QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559210#6193. Junk Problempandapythoner#AC ✓16ms6336kbC++234.8kb2024-09-11 20:50:222024-09-11 20:50:22

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 20:50:22]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:6336kb
  • [2024-09-11 20:50:22]
  • 提交

answer

#include <bits/stdc++.h>


using namespace std;

using ll = long long;
using ld = long double;

#define len(a) ((int)(a).size())
#define rep(i, n) for(int i = 0; i < (n); i += 1)


mt19937 rnd(234);

const ll MOD = 998244353, SZ = 210, GR_SZ = 100'100;
ll bpow(ll a, ll p) {
    if (p == 0) return 1ll;
    if (p % 2) return (bpow(a, p - 1) * a) % MOD;
    ll b = bpow(a, p / 2);
    return (b * b) % MOD;
}
ll det(vector<vector<ll>>& matr) {
    int s = matr.size();

    ll det = 1;
    for (int i = 0; i < s; ++i) {
        int ind = -1;
        for (int j = i; j < s; ++j) {
            if (matr[j][i] != 0) {
                ind = j;
                break;
            }
        }
        if (ind == -1) return 0;
        if (i != ind) {
            matr[i].swap(matr[ind]);
            det *= bpow(MOD - 1, MOD - 2);
            det %= MOD;
        }

        ll rv = bpow(matr[i][i], MOD - 2);
        det *= matr[i][i];
        det %= MOD;
        for (int t = 0; t < s; ++t) {
            matr[i][t] *= rv;
            matr[i][t] %= MOD;
        }

        for (int j = i + 1; j < s; ++j) {
            ll mul = matr[j][i];
            for (int t = 0; t < s; ++t) {
                matr[j][t] -= matr[i][t] * mul % MOD;
                if (matr[j][t] < 0) matr[j][t] += MOD;
            }
        }
    }

    /*for (int i = 0; i < s; ++i) {
        for (int j = 0; j < s; ++j) {
            cerr << matr[i][j] << " ";
        }
        cerr << endl;
    }*/
    return det;
}

int n, m, l, k;

map<pair<int, int>, int> ins, outs;
vector<int> gr[GR_SZ];
int lst = 0, used[GR_SZ], t = 1;
vector<int> tpsrt;
int dp[GR_SZ];

void tps(int v) {
    used[v] = t;

    for (auto to : gr[v]) {
        if (used[to] != t) {
            tps(to);
        }
    }

    tpsrt.push_back(v);
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    cin >> n >> m >> l >> k;

    vector<pair<int, int>> starts(l), ends(l);
    vector<int> sts, nds;
    for (int i = 0; i < l; ++i) {
        cin >> starts[i].second;
        --starts[i].second;
        starts[i].first = 0;
    }
    for (int i = 0; i < l; ++i) {
        cin >> ends[i].second;
        --ends[i].second;
        ends[i].first = n - 1;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ++lst;
            ins[{i, j}] = outs[{i, j}] = lst;
        }
    }

    set<pair<int, int>> bad;

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        bad.insert({ x, y });
        ++lst;
        outs[{x, y}] = lst;
        ++lst;
        outs[{x, y + 1}] = lst;

        gr[ins[{x, y}]].push_back({ outs[{x, y}] });

        //cerr << i << " in: " << lst + 1 << endl;
        ++lst;
        gr[ins[{x, y}]].push_back(lst);
        gr[ins[{x, y + 1}]].push_back(lst);
        nds.push_back(lst);
        //cerr << i << " out: " << lst + 1 << endl;
        ++lst;
        gr[lst].push_back(outs[{x, y}]);
        gr[lst].push_back(outs[{x, y + 1}]);
        sts.push_back(lst);
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ++lst;
            if (i + 1 < n) gr[outs[{i, j}]].push_back(ins[{i + 1, j}]);
            if (j + 1 < m && !bad.count({ i, j })) gr[outs[{i, j}]].push_back(ins[{i, j + 1}]);
        }
    }

    /*cerr << "GRAPH: " << endl;
    for (int v = 0; v < 14; ++v) {
        for (auto to : gr[v]) {
            cerr << v << " " << to << endl;
        }
    }*/

    for (auto c : starts) sts.push_back(ins[c]);
    for (auto c : ends) nds.push_back(outs[c]);

    vector<vector<ll>> matr(sts.size(), vector<ll>(nds.size()));

    /*for (auto c : sts) cerr << c << " ";
    cerr << endl;
    for (auto c : nds) cerr << c << " ";
    cerr << endl;*/

    for (int i = 0; auto c : sts) {
        ++t;
        tpsrt.clear();
        tps(c);
        reverse(tpsrt.begin(), tpsrt.end());
        for (int i = 0; i < GR_SZ; ++i) dp[i] = 0;
        dp[c] = 1;
        /*if (c == 8) {
            cerr << "TPS: " << tpsrt.size() << " " << c << endl;
            for (auto c : tpsrt) cerr << c << " ";
            cerr << endl;
        }*/
        for (auto v : tpsrt) {
            for (auto to : gr[v]) {
                dp[to] += dp[v];
                if (dp[to] >= MOD) dp[to] -= MOD;
            }
        }
        for (int j = 0; auto e : nds) {
            //if (i == 0) cerr << "Here" << e << " " << dp[e] << endl;
            matr[i][j] = dp[e];
            ++j;
        }
        ++i;
    }

    /*cerr << "Matr: " << endl;
    for (auto c : matr) {
        for (auto cc : c) cerr << cc << " ";
        cerr << endl;
    }
    cerr << "det: " << endl;*/

    cout << det(matr) << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4216kb

input:

2 2 1 2
2
1
1 1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3996kb

input:

3 4 2 1
1 4
1 4
2 2

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 4012kb

input:

10 10 3 4
1 2 3
8 9 10
2 3
2 5
4 6
7 8

output:

388035318

result:

ok 1 number(s): "388035318"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4016kb

input:

10 10 5 0
1 2 3 4 8
4 6 8 9 10

output:

534075044

result:

ok 1 number(s): "534075044"

Test #5:

score: 0
Accepted
time: 1ms
memory: 4280kb

input:

10 10 5 10
1 2 3 6 9
6 7 8 9 10
5 7
1 7
8 8
8 1
9 2
9 7
10 1
7 2
6 7
6 1

output:

113105350

result:

ok 1 number(s): "113105350"

Test #6:

score: 0
Accepted
time: 1ms
memory: 6132kb

input:

10 10 5 20
1 2 4 6 8
1 3 4 6 8
9 6
6 5
9 8
2 9
7 6
9 3
8 3
5 4
3 8
4 5
5 9
3 3
4 2
4 8
8 5
10 7
1 8
7 3
5 2
1 5

output:

312012

result:

ok 1 number(s): "312012"

Test #7:

score: 0
Accepted
time: 1ms
memory: 4028kb

input:

10 10 5 30
1 3 5 6 8
6 7 8 9 10
9 9
8 7
4 8
10 6
3 9
9 6
7 1
1 5
5 4
2 9
7 5
3 3
8 2
2 5
1 9
6 2
8 5
6 5
8 9
3 7
3 1
10 2
4 3
2 2
6 9
7 3
7 8
1 7
4 1
4 6

output:

720108525

result:

ok 1 number(s): "720108525"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

10 10 1 0
1
3

output:

55

result:

ok 1 number(s): "55"

Test #9:

score: 0
Accepted
time: 1ms
memory: 4024kb

input:

10 10 2 10
2 6
5 6
8 1
9 3
3 7
9 8
7 8
7 1
2 4
8 7
5 5
6 9

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 4120kb

input:

10 10 3 20
3 4 5
4 6 9
2 3
3 2
1 9
7 5
10 7
6 9
3 4
5 1
1 6
5 6
8 4
10 1
5 3
7 7
4 7
9 6
10 5
3 6
5 8
8 8

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 0ms
memory: 4064kb

input:

10 10 4 30
1 2 3 4
5 6 7 9
10 1
8 1
1 2
5 7
2 3
10 8
7 9
5 3
6 2
9 9
9 1
2 7
10 4
4 4
4 8
7 7
6 7
7 1
4 2
5 1
9 6
9 3
2 9
3 9
3 7
3 5
7 4
1 4
1 9
8 5

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 4092kb

input:

10 10 6 30
3 4 5 6 7 8
5 6 7 8 9 10
3 4
10 8
9 6
6 5
6 9
1 9
2 4
10 6
7 4
7 6
6 7
3 8
7 2
5 5
1 1
2 1
8 1
4 3
8 6
5 9
2 6
8 4
1 7
5 2
3 2
1 4
2 8
8 9
6 1
4 5

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 1ms
memory: 4092kb

input:

10 10 7 30
1 2 3 4 5 9 10
2 3 4 7 8 9 10
9 3
10 4
2 3
2 8
5 3
2 6
1 4
7 1
6 4
3 5
6 9
10 2
4 6
5 6
7 6
4 3
8 7
6 6
9 5
8 4
7 4
1 8
5 8
3 7
9 8
7 8
8 1
3 3
10 6
8 9

output:

58415340

result:

ok 1 number(s): "58415340"

Test #14:

score: 0
Accepted
time: 1ms
memory: 4024kb

input:

10 10 4 20
1 2 5 7
5 7 8 10
10 3
3 2
10 6
9 7
9 4
1 4
8 6
6 3
7 5
3 8
2 3
4 6
6 8
7 8
3 6
8 8
6 6
4 2
4 9
1 1

output:

212921229

result:

ok 1 number(s): "212921229"

Test #15:

score: 0
Accepted
time: 1ms
memory: 4032kb

input:

10 10 6 20
1 2 4 7 8 9
3 4 5 8 9 10
3 5
6 5
4 5
6 1
1 8
8 8
2 5
4 9
6 3
4 2
4 7
5 2
9 7
3 8
2 2
9 4
7 6
1 4
8 5
2 7

output:

215578944

result:

ok 1 number(s): "215578944"

Test #16:

score: 0
Accepted
time: 1ms
memory: 4208kb

input:

100 10 6 20
1 2 3 4 6 7
2 4 5 6 7 9
17 6
46 9
76 2
75 4
27 6
22 4
5 1
33 7
78 1
38 7
83 9
32 5
97 3
25 8
90 3
50 7
87 1
61 3
39 1
28 9

output:

266132935

result:

ok 1 number(s): "266132935"

Test #17:

score: 0
Accepted
time: 2ms
memory: 4500kb

input:

100 10 5 20
1 2 3 4 5
2 5 6 8 9
73 2
56 8
57 9
60 3
5 8
74 3
92 2
72 9
17 4
61 8
41 7
88 8
91 4
52 7
50 4
94 9
64 7
27 6
14 7
4 2

output:

558957370

result:

ok 1 number(s): "558957370"

Test #18:

score: 0
Accepted
time: 1ms
memory: 4456kb

input:

100 10 3 20
6 7 9
6 9 10
90 4
72 2
19 1
19 9
64 3
85 3
66 7
66 5
19 6
84 5
16 1
55 6
74 4
31 3
73 4
52 2
32 9
87 2
4 8
70 2

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 2ms
memory: 4444kb

input:

100 10 4 30
2 5 6 7
2 6 8 9
52 1
26 6
39 8
44 9
38 5
11 9
47 3
46 5
42 9
14 2
65 7
68 5
44 1
20 2
42 7
12 4
6 8
73 5
87 2
17 2
28 8
100 4
25 1
3 1
8 2
12 6
36 3
3 3
86 1
95 7

output:

803776201

result:

ok 1 number(s): "803776201"

Test #20:

score: 0
Accepted
time: 2ms
memory: 4264kb

input:

100 10 5 50
1 2 3 4 5
2 3 8 9 10
8 1
45 7
69 9
85 6
51 8
40 2
85 4
67 7
65 3
28 7
98 7
94 3
47 5
50 3
44 3
76 8
50 9
48 7
81 9
16 4
70 5
22 3
80 3
22 6
33 3
57 2
4 5
6 5
18 9
74 5
11 5
14 2
3 4
3 1
68 4
37 5
93 7
42 8
78 6
71 2
27 7
57 7
96 6
69 1
30 2
9 6
39 8
54 8
2 3
78 4

output:

463426103

result:

ok 1 number(s): "463426103"

Test #21:

score: 0
Accepted
time: 2ms
memory: 4264kb

input:

100 10 6 50
3 4 5 6 8 9
5 6 7 8 9 10
56 1
39 8
84 6
4 4
66 6
88 8
95 8
24 9
78 2
54 5
85 1
3 4
81 5
36 6
69 9
47 1
60 2
26 9
68 9
8 3
13 2
31 3
25 2
72 3
88 3
81 9
97 1
67 1
90 4
86 6
74 8
56 7
50 6
94 5
67 5
49 3
42 7
42 5
53 7
87 1
80 3
12 6
96 6
58 7
15 9
46 7
89 3
17 6
71 6
6 5

output:

123434985

result:

ok 1 number(s): "123434985"

Test #22:

score: 0
Accepted
time: 0ms
memory: 4220kb

input:

10 100 3 50
14 20 52
44 57 68
1 24
8 43
2 26
6 57
5 56
3 85
2 3
10 80
4 18
9 30
6 6
5 3
4 91
5 50
9 37
4 66
10 10
9 7
7 15
7 46
4 15
2 68
9 50
8 39
5 5
8 64
9 4
5 79
8 59
9 19
10 23
7 19
8 6
5 38
8 92
6 93
5 94
1 21
6 85
5 71
4 60
9 23
3 61
2 76
4 21
8 82
6 99
9 55
3 96
9 64

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 2ms
memory: 4520kb

input:

10 100 5 50
12 14 45 50 54
20 24 68 80 88
5 37
10 43
5 86
1 18
6 40
2 83
8 64
6 97
4 31
2 59
3 63
6 17
1 57
5 92
4 9
3 96
9 88
6 71
8 93
10 32
2 32
2 3
6 60
5 57
8 86
4 23
4 40
7 84
10 51
8 83
5 10
8 75
5 44
7 43
1 65
10 20
1 15
3 71
1 30
2 98
8 14
1 92
5 69
10 53
8 48
4 43
3 92
6 74
5 41
3 67

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 2ms
memory: 4176kb

input:

10 100 7 50
11 13 21 32 35 67 89
41 56 70 75 90 91 92
3 49
8 39
5 39
1 66
7 15
5 73
8 22
6 24
7 40
1 87
6 28
6 30
3 14
9 40
2 77
5 24
1 63
7 29
6 73
4 19
8 63
10 88
6 56
7 70
7 79
4 56
3 96
2 79
5 85
3 39
7 35
3 35
6 87
1 48
10 38
1 42
3 53
4 60
1 12
9 94
9 4
8 50
9 62
10 60
4 50
7 23
3 81
4 98
2 57...

output:

0

result:

ok 1 number(s): "0"

Test #25:

score: 0
Accepted
time: 11ms
memory: 6280kb

input:

100 100 10 50
4 11 20 24 33 37 38 57 60 71
42 47 48 62 68 80 84 87 91 95
28 22
49 40
89 44
72 33
66 29
99 80
38 92
18 80
36 73
63 26
65 31
48 52
84 6
34 95
37 80
3 94
23 40
37 84
42 75
33 49
97 13
37 19
57 92
78 5
92 89
82 49
23 36
95 85
64 23
86 88
97 51
50 55
51 53
66 67
100 95
54 39
50 34
23 32
9...

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: 0
Accepted
time: 13ms
memory: 6096kb

input:

100 100 20 50
1 2 9 11 12 15 17 18 20 22 25 34 45 52 56 59 67 71 78 83
23 25 29 35 37 38 53 61 67 68 69 77 80 81 82 85 87 91 95 96
100 15
13 38
42 54
11 31
28 31
14 56
17 5
51 46
59 40
5 72
24 41
100 77
42 70
81 96
3 27
60 9
21 36
40 90
99 51
59 57
51 63
96 29
6 17
23 41
3 45
5 4
84 22
21 63
19 6
59...

output:

0

result:

ok 1 number(s): "0"

Test #27:

score: 0
Accepted
time: 13ms
memory: 5956kb

input:

100 100 30 50
6 9 10 11 14 16 17 18 19 20 21 22 24 25 26 28 30 31 32 39 48 51 58 63 64 65 67 73 78 82
33 34 38 40 42 50 52 53 54 56 60 62 64 68 70 71 74 80 81 84 86 87 88 89 90 95 97 98 99 100
77 7
74 44
83 60
58 21
91 40
30 37
97 9
84 19
78 11
46 23
90 54
40 94
3 46
24 93
65 73
16 34
24 36
40 88
57...

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 15ms
memory: 5968kb

input:

100 100 40 50
1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 22 26 27 30 33 34 37 38 39 44 45 50 53 54 56 57 62 63 65 66 67 71 77 78
16 19 20 32 33 35 39 41 47 48 52 53 56 61 62 64 65 66 69 70 72 74 75 76 77 78 81 82 83 84 86 87 88 89 90 96 97 98 99 100
57 4
43 42
36 70
93 11
49 46
41 17
76 14
4 92
92 88
7...

output:

696316238

result:

ok 1 number(s): "696316238"

Test #29:

score: 0
Accepted
time: 11ms
memory: 6132kb

input:

100 100 50 50
4 5 6 7 9 10 11 12 13 14 15 16 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 35 39 40 41 44 45 46 49 50 51 52 53 57 60 64 66 73 77 78 80 82 92 98
23 26 29 33 35 36 39 41 42 47 48 49 54 55 56 57 58 59 60 61 62 63 64 66 68 70 71 72 73 74 76 77 79 81 82 83 84 88 89 90 91 92 93 94 95 96 97 ...

output:

0

result:

ok 1 number(s): "0"

Test #30:

score: 0
Accepted
time: 12ms
memory: 5992kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 17 18 19 20 21 22 25 26 28 29 31 32 33 36 37 38 39 40 41 42 43 44 45 46 47 50 57 59 62 63 64 65 70 71 77 78
4 6 10 13 29 32 37 41 43 44 46 47 52 53 55 58 62 63 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

55822359

result:

ok 1 number(s): "55822359"

Test #31:

score: 0
Accepted
time: 12ms
memory: 6040kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 31 32 34 35 36 37 38 39 40 41 47 48 49 50 51 52 53 55 60 65 67 68
20 24 28 31 33 35 40 45 46 54 55 56 57 58 59 61 62 63 66 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

268820259

result:

ok 1 number(s): "268820259"

Test #32:

score: 0
Accepted
time: 16ms
memory: 6100kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 20 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 41 42 43 46 51 52 55 56 57 58 59 60 63 66 69 80 91
7 18 23 25 26 36 37 38 40 44 47 48 51 54 55 60 63 64 65 66 67 69 70 71 72 73 75 77 78 79 80 81 82 83 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

252789512

result:

ok 1 number(s): "252789512"

Test #33:

score: 0
Accepted
time: 16ms
memory: 6336kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 20 21 22 23 25 26 27 28 29 30 31 32 35 39 40 41 42 44 46 47 51 52 53 57 58 59 64 66 69 78 79 85 86
18 23 28 30 31 32 33 34 35 38 42 43 47 49 53 55 58 61 63 64 65 66 68 70 71 74 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

604525399

result:

ok 1 number(s): "604525399"