QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797768#9647. 数位 DPDanielQOJ40 106ms69768kbC++143.2kb2024-12-03 17:52:282024-12-03 17:52:31

Judging History

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

  • [2024-12-03 17:52:31]
  • 评测
  • 测评结果:40
  • 用时:106ms
  • 内存:69768kb
  • [2024-12-03 17:52:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
int n, k, q;
string s;
int a[1005];
ui ksm(ui x, int y){
    ui ans = 1;
    while(y){
        if(y&1)ans = ans * x;
        y >>= 1;
        x = x * x;
    }
    return ans;
}
int c[1005];
ui ans;
int m;
ui dp[1005][1<<16];
int p[1<<16];
ui KSM[1005][105];
ui ANS[55][1<<16][17];
bool vis[55][1<<16][17];
int rk[1005];
int ord[1005];
ui calc(int n, int m, int K, int bh){
    if(vis[ord[n]][m][K]){
        return ANS[ord[n]][m][K];
    }
    ui ans = 0;
    for(int i = (n?min(31/n,K - 1):K-1); i >= 0; i--){
        if(m>>i&1){
            int num = __builtin_popcount(m>>i+1);
            if(1ll * i * n < 32){
                ans += ((ui)1 << i * n) * KSM[bh][num];
            }
        }
    }
    ans = -ans;
    if(1ll * K * n < 32)ans += (ui)1<<K*n;
    vis[ord[n]][m][K] = 1;
    return ANS[ord[n]][m][K] = ans;
}
signed main(){
    // freopen("dp.in", "r", stdin);
    // freopen("dp.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> k >> q;
    cin >> s;
    int ok = 1;
    for(auto i : s){
        if(i == 'A')ok = 0;
    }
    if(ok){
        while(q--){
            cin >> m;
            int bh = -1, K = k;
            ui ans = 0;
            for(int i = (n?min(31/n,K - 1):K-1); i >= 0; i--){
                if(m>>i&1){
                    int num = __builtin_popcount(m>>i+1);
                    if(1ll * i * n < 32){
                        ans += ((ui)1 << i * n) * (bh==-1?ksm(n,num): KSM[bh][num]);
                    }
                }
            }
            ans = -ans;
            if(1ll * K * n < 32)ans += (ui)1<<K*n;
            cout << ans << '\n';
        }
        return 0;
    }
    for(int i = 0; i < 1<<16; i++){
        p[i] = k;
        for(int j = 0; j < 16; j++){
            if(i>>j&1){
                p[i] = j;
                break;
            }
        }
    }
    vector<int>vec;
    set<int>st;
    for(int i = 1; i <= n; i++){
        int en = i;
        while(en + 1 <= n && s[en-1] != 'A')en++;
        vec.emplace_back(en - i + 1);
        i = en;
    }
    for(int i = 1; i <= vec.size(); i++){
        for(int j = 0; j <= k; j++){
            KSM[i][j] = ksm(vec[i-1] - (i!=1), j);
        }
        st.insert(vec[i-1]-(i!=1));
    }
    vector<int>vecc;
    for(auto i : st){
        vecc.emplace_back(i);
        ord[i] = vecc.size() - 1;
    }
    while(q--){
        cin >> m;
        for(int i = 0; i <= vec.size(); i++){
            for(int j = 0; j < (1<<k); j++){
                dp[i][j] = 0;
            }
        }
        dp[vec.size()][m] = 1;
        for(int i = vec.size(); i >= 1; i--){
            for(int j = 0; j < (1<<k); j++){
                if(!dp[i][j])continue;
                for(int w = j; ; w = (w-1) & j){
                    int num = __builtin_popcount((j^w) >> p[w]);
                    dp[i - 1][w] += dp[i][j] * KSM[i][num] * calc(vec[i-1] - (i!=1), (j^w) & (1<<p[w])-1, p[w], i) * (i==1?1:(ui)(((ui)1<<k)-w));
                    if(!w)break;
                }
            }
        }
        cout << dp[0][0] << '\n';
    }
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 2ms
memory: 11784kb

input:

4 5 200
AAA
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

output:

1
16
81
256
625
1296
2401
4096
6561
10000
14641
20736
28561
38416
50625
65536
83521
104976
130321
160000
194481
234256
279841
331776
390625
456976
531441
614656
707281
810000
923521
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
104857...

result:

ok 200 lines

Test #2:

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

input:

4 5 200
XXX
15
29
23
29
23
15
30
27
27
23
30
29
27
23
30
23
27
23
30
30
30
30
15
29
27
23
15
30
15
27
27
23
15
30
29
27
23
23
15
23
27
27
27
29
23
30
29
30
27
27
30
27
27
15
27
15
23
23
27
15
23
30
30
29
30
15
30
15
29
15
27
29
15
29
30
30
15
29
15
27
27
15
27
27
30
27
30
30
15
30
29
27
30
23
27
27
...

output:

1043136
962496
981696
962496
981696
1043136
961536
966336
966336
981696
961536
962496
966336
981696
961536
981696
966336
981696
961536
961536
961536
961536
1043136
962496
966336
981696
1043136
961536
1043136
966336
966336
981696
1043136
961536
962496
966336
981696
981696
1043136
981696
966336
966336...

result:

ok 200 lines

Test #3:

score: 10
Accepted
time: 2ms
memory: 12084kb

input:

4 5 200
AXA
18
10
11
16
27
4
15
15
9
17
29
18
30
9
24
20
20
6
31
1
11
2
7
9
29
6
26
12
28
18
20
0
12
10
25
11
6
31
30
26
27
20
17
3
24
0
8
23
7
3
14
5
15
24
22
6
21
5
27
6
10
19
16
15
0
28
29
23
9
15
28
14
19
26
30
24
6
2
9
22
23
20
13
12
18
15
25
10
17
2
5
11
4
13
26
13
6
22
25
15
23
25
30
19
10
17...

output:

281568
632544
599340
327680
72280
890624
447576
447576
668702
305790
38328
281568
23936
668702
122880
228864
228864
814944
11440
1013855
599340
975600
777900
668702
38328
814944
88512
550400
52224
281568
228864
1048576
550400
632544
106428
599340
814944
11440
23936
88512
72280
228864
305790
939542
1...

result:

ok 200 lines

Test #4:

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

input:

4 5 200
AAA
2
1
6
16
0
20
5
25
24
27
10
5
25
14
2
3
18
11
5
27
23
21
19
7
25
20
25
15
29
20
5
11
25
1
19
6
13
18
31
30
17
14
10
12
16
18
29
27
24
2
23
24
26
14
18
29
6
9
21
0
18
27
10
12
6
0
20
6
29
25
18
18
27
6
29
10
23
19
24
15
6
22
11
9
5
25
19
9
14
0
22
30
3
13
19
13
15
10
5
21
14
21
27
3
31
25...

output:

810000
923521
456976
65536
1048576
20736
531441
2401
4096
625
234256
531441
2401
104976
810000
707281
38416
194481
531441
625
6561
14641
28561
390625
2401
20736
2401
83521
81
20736
531441
194481
2401
923521
28561
456976
130321
38416
1
16
50625
104976
234256
160000
65536
38416
81
625
4096
810000
6561...

result:

ok 200 lines

Test #5:

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

input:

4 5 200
OOX
9
13
15
3
12
7
25
14
30
31
10
10
5
29
28
2
31
16
24
9
9
16
25
7
7
22
3
17
29
10
30
19
27
20
3
24
5
11
23
17
30
14
31
19
20
11
4
15
23
2
26
26
13
25
12
15
28
22
25
13
28
13
4
19
8
14
19
17
21
21
5
6
19
23
16
28
4
16
31
22
11
28
22
5
31
30
24
11
30
25
10
28
4
23
28
0
6
10
28
10
17
22
26
5
...

output:

1044476
1043440
1043136
1048556
1043456
1048240
966640
1043200
961536
961280
1044416
1044416
1048316
962496
962560
1048560
961280
983040
966656
1044476
1044476
983040
966640
1048240
1048240
981760
1048556
983036
962496
1044416
961536
982960
966336
982016
1048556
966656
1048316
1044400
981696
983036
...

result:

ok 200 lines

Test #6:

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

input:

4 5 200
AAA
10
22
27
29
26
14
19
23
7
30
19
9
20
25
15
2
30
2
27
25
19
5
28
23
10
20
26
15
13
8
0
13
31
17
22
0
31
9
30
27
31
13
29
11
23
26
12
9
21
22
3
6
27
18
25
28
25
6
27
21
0
27
13
19
31
29
11
14
11
9
10
18
13
26
22
3
17
11
7
29
23
26
6
17
11
27
30
18
18
12
8
29
14
4
2
22
31
13
19
20
24
23
6
3...

output:

234256
10000
625
81
1296
104976
28561
6561
390625
16
28561
279841
20736
2401
83521
810000
16
810000
625
2401
28561
531441
256
6561
234256
20736
1296
83521
130321
331776
1048576
130321
1
50625
10000
1048576
1
279841
16
625
1
130321
81
194481
6561
1296
160000
279841
14641
10000
707281
456976
625
38416...

result:

ok 200 lines

Test #7:

score: 10
Accepted
time: 2ms
memory: 11888kb

input:

4 5 200
AAA
21
18
31
9
21
8
4
11
25
24
26
18
29
18
15
27
16
27
13
18
21
22
27
11
31
17
12
26
14
12
4
1
13
19
27
2
24
6
9
5
19
22
31
30
7
24
22
11
20
9
29
21
13
23
9
14
30
24
30
26
3
20
25
31
3
17
2
15
6
29
12
12
26
25
1
25
4
13
15
25
5
28
22
14
12
5
9
10
26
27
19
27
28
14
4
22
8
20
17
22
30
29
17
31...

output:

14641
38416
1
279841
14641
331776
614656
194481
2401
4096
1296
38416
81
38416
83521
625
65536
625
130321
38416
14641
10000
625
194481
1
50625
160000
1296
104976
160000
614656
923521
130321
28561
625
810000
4096
456976
279841
531441
28561
10000
1
16
390625
4096
10000
194481
20736
279841
81
14641
1303...

result:

ok 200 lines

Test #8:

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

input:

4 5 200
OXX
29
17
13
0
4
0
0
15
14
21
18
9
13
27
16
27
29
30
4
31
3
23
31
9
23
20
9
29
28
1
26
7
26
21
17
27
18
25
23
14
13
14
30
6
25
24
15
28
0
6
14
10
7
13
26
22
9
5
20
15
21
23
20
22
9
27
18
6
17
3
26
31
12
20
26
6
19
17
5
13
26
31
18
30
18
30
20
31
27
18
29
29
2
31
28
6
0
7
6
22
18
28
9
13
12
2...

output:

962496
983036
1043440
1048576
1048320
1048576
1048576
1043136
1043200
982000
982976
1044476
1043440
966336
983040
966336
962496
961536
1048320
961280
1048556
981696
961280
1044476
981696
982016
1044476
962496
962560
1048575
966400
1048240
966400
982000
983036
966336
982976
966640
981696
1043200
1043...

result:

ok 200 lines

Test #9:

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

input:

4 5 200
XAA
30
14
15
21
5
17
14
25
14
20
20
9
11
10
11
1
5
4
9
17
24
29
26
5
20
12
30
3
14
31
31
5
22
23
3
2
28
12
26
23
9
18
20
26
25
3
16
26
2
23
24
1
12
9
18
25
19
20
19
3
12
11
4
20
25
5
22
14
15
22
11
7
23
5
10
24
18
0
9
10
23
19
22
15
26
30
26
20
12
19
25
6
23
24
11
19
18
31
29
28
18
18
26
5
2...

output:

2176
295488
261256
88572
733374
172350
295488
31164
295488
105984
105984
506782
418068
460768
418068
983103
733374
790272
506782
172350
40960
5112
22464
733374
105984
371200
2176
856138
295488
528
528
733374
72000
57672
856138
918000
9216
371200
22464
57672
506782
148960
105984
22464
31164
856138
19...

result:

ok 200 lines

Test #10:

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

input:

4 5 200
XXO
0
14
16
6
13
0
28
22
13
3
19
17
30
24
8
21
6
16
1
11
10
17
6
13
13
3
17
7
7
22
6
12
19
16
2
15
25
17
23
5
21
29
18
14
23
0
28
7
6
24
25
9
28
9
17
14
28
20
15
29
17
27
19
9
14
25
3
24
12
25
10
25
30
19
3
13
9
2
15
18
3
30
10
5
21
22
28
10
15
13
15
25
19
19
8
7
16
29
7
25
10
29
30
18
22
18...

output:

1048576
1043200
983040
1048256
1043440
1048576
962560
981760
1043440
1048556
982960
983036
961536
966656
1044480
982000
1048256
983040
1048575
1044400
1044416
983036
1048256
1043440
1043440
1048556
983036
1048240
1048240
981760
1048256
1043456
982960
983040
1048560
1043136
966640
983036
981696
10483...

result:

ok 200 lines

Subtask #2:

score: 10
Accepted

Test #11:

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

input:

20 8 20
AAAAAAAAAAAAAAAAAAA
255
254
253
252
251
250
249
248
247
246
245
244
243
242
241
240
239
238
237
236

output:

1
1048576
3486784401
0
1977800241
3104833536
3095271137
0
689956897
1661992960
1226119153
0
4176394193
1846542336
2980478145
0
1144323905
2182086656
2763774801
0

result:

ok 20 lines

Test #12:

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

input:

20 8 20
XXOOXXXOOOXOOXXXXXX
223
254
239
127
251
247
223
223
254
253
254
239
247
223
127
223
251
127
251
254

output:

3157225472
0
3157225472
3157225472
3157225472
3157225472
3157225472
3157225472
0
4230967296
0
3157225472
3157225472
3157225472
3157225472
3157225472
3157225472
3157225472
3157225472
0

result:

ok 20 lines

Test #13:

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

input:

20 8 20
AOAOAXAOAXAOAXAOAXA
1
139
141
253
49
89
100
235
106
169
177
199
27
63
169
104
191
54
239
54

output:

2596932351
444889112
642944536
3394047424
1995656860
1794163992
0
3083125088
3783262208
1396280088
2829574680
3125900656
2757493016
2952862816
1396280088
0
2713869248
3514826752
498553792
3514826752

result:

ok 20 lines

Test #14:

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

input:

20 8 20
AAAAAAXAAAAAAOAAAAA
182
64
25
84
227
184
255
183
201
39
43
232
217
63
4
94
85
164
120
175

output:

2580545536
0
841269017
0
4233876109
0
3196053143
4234287951
722457003
1479575031
4073032191
0
2835298401
89573919
0
1297088512
3057585635
0
0
2640696959

result:

ok 20 lines

Test #15:

score: 10
Accepted
time: 2ms
memory: 11836kb

input:

20 8 20
XXOOOXAOOXXOOAOXOXX
13
144
231
225
195
11
210
171
187
111
220
55
239
205
221
33
233
7
247
183

output:

1914607548
0
2820613408
4190143288
1349955368
4104752340
3682598912
763900496
850003872
344774176
0
3575735056
907161152
379632112
998910688
4293952878
1178842864
3866438084
3842625600
1048790816

result:

ok 20 lines

Test #16:

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

input:

20 8 20
AOXAXAAOAAXAAOAXOXX
40
187
158
14
49
213
39
29
254
181
46
220
231
142
40
90
206
88
36
191

output:

0
3193371575
835715072
4182769664
3263242009
3866789033
3429976231
1248772075
491782144
2441390825
946864128
0
2632295535
1047527424
0
3635412992
449839104
0
0
2726809173

result:

ok 20 lines

Test #17:

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

input:

20 8 20
AAAAAAAAAAAAAAAAOAX
141
207
65
228
151
65
57
252
94
252
199
62
47
228
194
151
255
55
238
61

output:

680445295
2794147121
2672008899
0
1498887811
2672008899
1254672067
0
565182464
0
715997235
3635412992
1301139995
0
110100480
1498887811
876053577
19247395
579862528
586255357

result:

ok 20 lines

Test #18:

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

input:

20 8 20
OXOAXXXAXOOAAOOAOOX
202
90
82
55
206
140
9
217
117
142
157
157
110
206
36
44
83
49
19
235

output:

1857028096
3828350976
1183842304
201104635
1857028096
0
1421874471
2356948025
3339221653
1884291072
142114461
142114461
397410304
1857028096
0
0
4020004345
3097298385
4204969527
550445409

result:

ok 20 lines

Test #19:

score: 10
Accepted
time: 2ms
memory: 14064kb

input:

20 8 20
AAAAAAAAAAAAAAAAAAA
117
85
62
163
251
104
153
178
187
114
155
237
75
61
231
30
69
9
222
106

output:

1504122353
46640497
4161798144
3797657873
1977800241
0
3554417505
2249195520
1941563185
2651848704
3039303601
2763774801
2490579697
4287090833
2881090913
1812987904
1915233073
611513377
4094689280
1863319552

result:

ok 20 lines

Test #20:

score: 10
Accepted
time: 1ms
memory: 9972kb

input:

20 8 20
XOXXXXXXOOOXAXOXXXX
41
169
154
217
104
167
76
158
178
90
201
227
187
90
26
239
5
34
183
210

output:

4294885121
4294006675
1752170496
4280995513
0
3331336011
0
1244659712
674234368
3195011072
4294156851
2856438223
1008201685
3195011072
2278555648
3165363643
67104071
1982857216
3855648865
2100297728

result:

ok 20 lines

Subtask #3:

score: 10
Accepted

Test #21:

score: 10
Accepted
time: 106ms
memory: 67184kb

input:

200 16 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
65535

output:

1

result:

ok single line: '1'

Test #22:

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

input:

200 16 1
OXOXXXOXXOXOXXOOOXXXXOOXXOOOXOOXOOXXOOOOXXOXOOXOXXXOXXXXXXXOXOXOOXOXXOOOXOOXXOOOXXXXOXXXOOXXOXOXOXXOOOOOOOOOOXXOXXXOXXOOOXOOXXXOOXXOXXOOOXOOOXOOOXOXXXXXOXOOOXXXXOXXXOOOOOOOXOOXOXXXXXOXOXOXOOXXXOXXOXX
63487

output:

0

result:

ok single line: '0'

Test #23:

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

input:

200 16 1
AXAXAXAOAOAXAXAOAOAXAXAOAOAOAXAOAOAOAXAOAOAOAOAXAXAOAOAXAOAOAOAXAOAXAXAOAOAOAXAOAXAOAXAOAOAOAOAXAXAXAXAXAXAOAXAOAOAOAOAXAXAOAXAXAOAXAXAOAXAOAOAXAOAOAXAXAOAXAOAXAOAOAOAOAOAOAOAOAXAXAOAOAOAOAOAOAXAOAOA
4359

output:

2017260928

result:

ok single line: '2017260928'

Test #24:

score: 10
Accepted
time: 14ms
memory: 54860kb

input:

200 16 1
AAAAAAOAAAAAAOAAAAAAXAAAAAAOAAAAAAXAAAAAAXAAAAAAXAAAAAAXAAAAAAOAAAAAAXAAAAAAXAAAAAAXAAAAAAOAAAAAAXAAAAAAOAAAAAAXAAAAAAOAAAAAAOAAAAAAOAAAAAAXAAAAAAOAAAAAAXAAAAAAOAAAAAAOAAAAAAOAAAAAAXAAAAAAXAAAAAAOAAA
8276

output:

0

result:

ok single line: '0'

Test #25:

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

input:

200 16 1
OOOOXOAOXXXOOAXXOOXOAXOXOXXAOOXXOXAXXXOOOAXOXOXOAOXXXOOAXXOOXXAOXOXOXAOXXOXXAOOOXOOAXOOXOOAOOOXXXAOXOOXOAOOOOOXAXOOOXOAXOXOOOAOXXOXXAOOOXOXAOOOOOOAOXXXOOAOOOOXXAOXOOXOAXXOXXXAXXXXOOAOOXXXXAOOXOOXAOOX
62733

output:

118423552

result:

ok single line: '118423552'

Test #26:

score: 10
Accepted
time: 6ms
memory: 67184kb

input:

200 16 1
XAXXAAOAOAOXOXAAAXAAXAAAXOAXAAXOXOAOAXOOAAAAAXAAOXAAAOOAOAAXAXXXOAOOOOXAAXAAAOAXOAAAXAAAAAAXOAAAAXAAOAAAAAOAAXOAOOXXAOAXOOAAAAOAAAAAAAAXXAAOAOOXAOAOAAAAAAAXAAXOAAOOAAXAAAXAAOAAXAXOXAXXXXOXXAOAAOAOAAA
36975

output:

3800841600

result:

ok single line: '3800841600'

Test #27:

score: 10
Accepted
time: 31ms
memory: 69756kb

input:

200 16 1
XAAXAXAAAAAXXAOAAOXAAAAXAAAAAAAAAAXOAAAAAAAXAAAAAAAOAAAAAOAAAAAAAAAOAAAAAOAAAAAAAAAAAAAAAAAAAAXAAAOOXAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAXAAOAAAAAAAAAAAAAAAOAAAAAXAAAAAAAAAAAAAAAAAAAAAAAXOAXAAAAAXAAAAAA
42961

output:

4143734528

result:

ok single line: '4143734528'

Test #28:

score: 10
Accepted
time: 56ms
memory: 36532kb

input:

200 16 1
XOOOXXXXOXXAOXXAOOXXOXAOXOOAOOOOAAXOAXOXXAOOOXXOOXOXOOXOXOXXXAOXOXOXOXXXAXOAOXXXOOOXXXXXOOOOOOXAOXXXAXOXXAOOOXXAOXOOXOOXOXXOXOXOOAOXOOAXAXXOXAOXXXXOOXAOXXOOXXOXAOOOOAXXAOOOXXOOXOOOXAOXXOXOAOXOXAOXOXX
32762

output:

0

result:

ok single line: '0'

Test #29:

score: 10
Accepted
time: 82ms
memory: 69768kb

input:

200 16 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXOAAAXAAXAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAXAAAAAAAAAAAAAAAAAAAOAAAAOAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAOAAAAAAAAAAAAAAAA
55979

output:

347602944

result:

ok single line: '347602944'

Test #30:

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

input:

200 16 1
AXXOOOOXOOOOOXOXOAXOOXOXOXAOXOOXXXOXOAOOAOOAOXOAOXXXXOXAAOXOOXXXXAOOOXOXOXXOAOXXOXOXXXXXOOXAXOOXOOOOOOXXXXOOXOOOOOXOXOOXXOOXOXXXXOOOAXXOXOAOOXXOOXAOXXOXOXOXXXOOAXOXXAXOOAXXXOXAOOOXXOOOAOOOXOAXOXOXOXO
30929

output:

3913125083

result:

ok single line: '3913125083'

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #31:

score: 0
Time Limit Exceeded

input:

200 16 200
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
65535
65534
65533
65532
65531
65530
65529
65528
65527
65526
65525
65524
65523
65522
65521...

output:


result:


Subtask #5:

score: 0
Runtime Error

Dependency #3:

100%
Accepted

Test #41:

score: 0
Runtime Error

input:

200 30 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
527009106

output:


result:


Subtask #6:

score: 10
Accepted

Test #51:

score: 10
Accepted
time: 1ms
memory: 3816kb

input:

1000 30 1000
XOOXOOXOOXXOXOXOOOXOXXOXOXXXOXXOXOOOXXOXOXOXXXXOOOOXOOXOXXOOOXXOXOOXOOOOOOXOOXOXXOXXXOOXXXOXXXOXXXOOOOXXXOOXXXXXXXXOXOOOOXOOOOXXOXXXXXXXXXOXOOXOOXOOOXXXXXXOOXXOXOOXXOXXXXXOOXOOOXXOOXOOXOXOOOOXXXOXOOXOXOXXXXOOXOXOOXXXXXOXOOXXXXXOXXOXOXXOXOOXOXOOOOXXOXOOXXXXOOXXOXXOOXXXXOXXOOXXXOOXOOOXOXO...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #52:

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

input:

1000 30 1000
XXOOXXXOOOXOXXXXOOXXXXXOXOOXOXXOXXXOXXOXOOOOXXXXOOXXXOOXXXOOOXOOOOOXOOOOXXXXOXXOXOOXXOXXXOXOOXXOXOXOXOXOOOOXOOOXXXOOOOOOOOOXXOOOOOXOOXOOXOOXXXOOOXXXOXOOOXXXOOOXXOOXOOOXXXOXOOOXOXXOXXXOOOOXOXXOOOOOXOOOOOXXOXOOXXOXOXXOOXXOXXXXXXXXOOXOOOOXXOOXXXOOXOXXOXOXOXXXXOOOXXOOXXOOXXOOXOXOOXXOOOXXXOX...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #53:

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

input:

1000 30 1000
XXOXOXXOOOXXXOXXXOXOOXXOOXXXXOXOOOXXXXOOOOOXOOOOOOOXOXOOXXOOXXOOOXOXXXOOXXXXXXOXXXOOOOXXOXOXOOXXOOOXXOXOXOOOOXXXXOOXXXXXOOXOOXOXXOXXXXOOXOXOXOXOOOOOOOOOOXXOOOXXOXXXXXOXOXOXXXOXOXXOXXXXOOOOOOXOOXOOXXOOOOOOOOXXXXOXOOXOOOOOOXOOXXXXOXXOOXXOXXXXXXXXOXXXXOOOXXXXOOXOOXOXXOOOOOXOOXXXXOOXXOOXOOO...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
402653184
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3221225472
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 1000 lines

Test #54:

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

input:

1000 30 1000
XXOXXOXXOXOXXXXXOXXOXOOXXXOXXOXXOOOOOXXXXOXOOOXOXOXXX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
0
0
1593835520
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1530494976
0
0
0
0
0
0
0
0
0
0...

result:

ok 1000 lines

Test #56:

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

input:

1000 30 1000
XOOOOOXOOOOXXOXXXOXXXXXXXXXXOXOOXXXXXXXOXXOOOXXOXXXXXXXXXOXXXXOXXOOOXOOOXXOXXOXOOOXXXOXXOOXOOOXOOOXOOOXOXOXXXXXOOOOXOOOOXXXOXOOOXXXOOXXOOXOXXXOOXOXOOXXXOXOXXOXXXXOXXXOOXOOOOXXXXOOOOXXOOXXXXOXOXOOOXXOXOOXOOXOXXXOXOOXOXOXOXOOOXXXXOXOOXXOOXOOXOXXOOOXXXXOOOOXXXOOXXXXOOOOXXXXXXXXOXOXOOXXOXXO...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3221225472
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3221225472
0
0
0
0
3221225472
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 1000 lines

Test #57:

score: 10
Accepted
time: 1ms
memory: 3884kb

input:

1000 30 1000
XOXXXOXOOOOOOXOOXOOOOOXXXXXOOOXXXOXOXOXXOOOXXOOXXOOXOOOOOXOXXXXOXOOXOOXOXXXOOXOXOXOOXXXXXXXOXOOOOOOXXXOXOXOOOOOOXXXXXOOXXXXXXXXOXOOOOOXXOXOXOXOOOOXOXXOOOOXOOOXXOOXOXXOOOOOXXOOXOXOOOXOOXOOOXOOOOXXOXXXOOOOXXXOX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000 lines

Test #59:

score: 10
Accepted
time: 1ms
memory: 3588kb

input:

1000 30 1000
OXXOOXOXOXOOXOOOXXOOXXXXXXOXOXOOOOXXXOOXXXOXXXOXXXOXXOOXXOXOXXOOXOXXXXXOOXOOXOXOOXXXXXOOOOXOXOOOXXXOOOOOOOXOXOXXXXXXOOXOXOOOXXXXOXOXXOOXXOXOOOXXXOXXXOOOOOXXOXXOOOXXOXXXOXXOXXXXXOOOOXXXXOXOXOOXXOXXOOOOOOXXOXXXXXXOXOXOOXOXOXOOXXOOOXOXOOOXXOXOOXOOOXXOXXOXXOOXXOXXXOXOXOOXXXXXOOXOOXXXXOXXOOX...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #60:

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

input:

1000 30 1000
XXXOOOXXXXXOXOXXXOXOXOOXOXOXXOXOOXXOOXXOXOOOOOXXOOXXOOOOOOXXOXXXOOOOXXXOOXXXXOXOXXXOOOOXOXXOOXOXXXOXXXOXXOOXOXXOXOXOXOOOOOXXOOOXOOOXOOOOXOOXOOXOXOOXOOOOOOOXOXOOXOXOOOOXOOOXXOOXXXOXOOXXXXXXOXOXOOXOOXXXXXXXOOOXOOOXOOOOXXXOXOOXXXXXXOOXOOXXOOOOXOOOXOXXOXOXOXXOXOOOOOOXOXXOXOXXOXXOXXOOXXXXOXX...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3221225472
0
3221225472
0
0
0
0
0
0
0
0
0
0
0
3221225472
0
0
402653184
0
0
0
0
0
0
0...

result:

ok 1000 lines

Subtask #7:

score: 0
Runtime Error

Dependency #2:

100%
Accepted

Test #61:

score: 0
Runtime Error

input:

50 30 50
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
1073741823
1073741822
1073741821
1073741820
1073741819
1073741818
1073741817
1073741816
1073741815
1073741814
1073741813
1073741812
1073741811
1073741810
1073741809
1073741808
1073741807
1073741806
1073741805
1073741804
1073741803
1073741802...

output:


result:


Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #4:

0%

Subtask #10:

score: 0
Skipped

Dependency #6:

100%
Accepted

Dependency #8:

0%