QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573430#4888. Decoding The MessagehhoppitreeWA 73ms6204kbC++172.9kb2024-09-18 18:43:122024-09-18 18:43:14

Judging History

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

  • [2024-09-18 18:43:14]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:6204kb
  • [2024-09-18 18:43:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 256;

int c[N], d[4];

int ksm(int x, int y, int P) {
    int res = 1;
    while (y) {
        if (y & 1) res = 1ll * res * x % P;
        x = 1ll * x * x % P;
        y >>= 1;
    }
    return res;
}

int solve(int mod) {
    int s = 0, n = 0;
    for (int i = 0; i < N; ++i) s += 1ll * c[i] * i % mod, n += c[i];
    s %= mod;
    if (!s) return 0;
    int fac = 1;
    for (int i = 1; i <= n && fac; ++i) fac = fac * i % (mod - 1);
    return ksm(s, fac, mod);
}

int dp[1 << 11][257];
bitset<257> f[605], g[605];

int calc() {
    int n = 0, mx = 0;
    for (int i = 0; i < N; ++i) n += c[i], mx = max(mx, c[i]);
    if (n <= 11) {
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        vector<int> o;
        for (int i = 0; i < N; ++i) {
            for (int j = 1; j <= c[i]; ++j) o.push_back(i);
        }
        for (int i = 1; i < 1 << n; ++i) {
            int od = __builtin_parity(i);
            for (int j = 0; j < n; ++j) {
                if ((i >> j) & 1) {
                    for (int k = 0; k < 257; ++k) {
                        int nw = (od ? k - o[j] + 257: k + o[j]) % 257;
                        dp[i][k] += dp[i ^ (1 << j)][nw];
                    }
                }
            }
        }
        int res = 1;
        for (int i = 0; i < 257; ++i) res = 1ll * res * ksm(i, dp[(1 << n) - 1][i], 257) % 257;
        return res;
    }
    if (n - mx > 600) return 0;
    for (int i = 0; i < 605; ++i) f[i].reset();
    f[0][0] = 1;
    vector<int> o;
    int tmx;
    for (int i = 0; i < N; ++i) if (c[i] == mx) tmx = i;
    for (int i = 0; i < N; ++i) {
        if (i != tmx) for (int j = 1; j <= c[i]; ++j) o.push_back(i);
    }
    for (int i = 0; i < (int)o.size(); ++i) {
        int x = o[i];
        for (int j = 0; j <= i; ++j) {
            g[j] |= f[j] << x;
            g[j] |= f[j] >> (257 - x);
            x = (257 - x) % 257;
            g[j + 1] |= f[j] << x;
            g[j + 1] |= f[j] >> (257 - x);
            x = (257 - x) % 257;
        }
        for (int j = 0; j <= i + 1; ++j) f[j] = g[j];
    }
    for (int i = max(n / 2 - (int)o.size(), 0); i <= mx && i <= n / 2; ++i) {
        for (int j = 0; j < 257; ++j) {
            if (f[n / 2 - i][j] && (j + 1ll * (mx - i) * tmx + 1ll * i * (257 - tmx)) % 257 == 0) return 0;
        }
    }
    return 1;
}

signed main() {
    int T; scanf("%d", &T);
    while (T--) {
        int n; scanf("%d", &n);
        fill(c, c + 256, 0);
        for (int i = 1, x, y; i <= n; ++i) scanf("%d%d", &x, &y), c[x] += y;
        d[0] = solve(3), d[1] = solve(5), d[2] = solve(17), d[3] = calc();
        for (int i = 0; ; ++i) {
            if (i % 3 == d[0] && i % 5 == d[1] && i % 17 == d[2] && i % 257 == d[3]) {
                printf("%d\n", i);
                break;
            }
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5916kb

input:

5
1
42 1
2
0 1
1 1
1
239 2
2
1 1
2 1
3
1 1
2 2
3 2

output:

42
256
514
1284
61726

result:

ok 5 number(s): "42 256 514 1284 61726"

Test #2:

score: 0
Accepted
time: 9ms
memory: 5916kb

input:

100
1
213 79
1
54 69
1
218 55
1
248 80
1
101 8
1
153 79
1
240 45
1
112 70
1
217 5
1
208 64
1
48 30
1
0 19
1
53 40
1
63 17
1
179 65
1
221 22
1
135 84
1
138 20
1
54 29
1
114 19
1
253 94
1
240 36
1
40 94
1
244 93
1
239 24
1
133 8
1
105 91
1
45 43
1
241 74
1
206 17
1
100 73
1
133 44
1
57 70
1
56 72
1
47...

output:

21846
21846
26215
59110
32896
6426
48060
59110
43570
32896
15420
0
59110
6426
26215
17476
15420
15420
21846
21846
32896
15420
59110
21846
54741
32896
48060
48060
32896
50116
26215
32896
15420
54741
6426
17476
15420
21846
54741
39321
54741
54741
6426
54741
1
59110
59110
26215
54741
15420
15420
22101
...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 4ms
memory: 3808kb

input:

100
1
208 74003161
1
108 37880052
1
102 289342450
1
190 16254190
1
20 507132853
1
1 842472902
1
212 226854721
1
33 797732105
1
213 114087750
1
128 914592259
1
27 779924279
1
203 425018504
1
217 458915584
1
139 710603120
1
226 84538604
1
50 602470204
1
150 228443262
1
48 593328022
1
24 35949157
1
148...

output:

1
54741
0
59110
26215
32896
1
48060
15420
1
21846
32896
32896
59110
32896
59110
15420
54741
21846
1
54741
26215
54741
32896
32896
54741
0
54741
21846
48060
32896
21846
32896
50116
50116
21846
15420
48060
59110
26215
15420
21846
1
54741
21846
48060
15420
54741
17476
48060
54741
6426
54741
59110
54741...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 4ms
memory: 4104kb

input:

100
2
14 231169007
169 438746441
1
106 224694504
1
11 18668998
1
94 173751742
1
248 424067991
1
132 301760918
1
192 82611030
1
165 348431335
2
25 205571031
27 312669004
1
244 137616146
2
199 365022194
197 490765328
2
151 270019586
159 158690083
1
169 403261990
1
246 138193758
2
38 426785000
53 20660...

output:

54741
54741
32896
32896
21846
54741
15420
48060
54741
32896
54741
32896
59110
54741
32896
26215
32896
59110
17476
32896
32896
32896
59110
32640
15420
43690
32896
21846
32896
32896
32896
59110
32896
15420
32896
54741
32896
32896
21846
26215
39321
54741
17476
1
32896
21846
48060
32896
32896
32896
1542...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 3860kb

input:

100
19
159 4447181
119 4122592
208 20865102
19 18177591
218 15143881
145 22831007
151 35147071
91 49145857
165 13456608
253 18740477
123 40212709
175 10592471
244 41909532
62 34807087
41 14303940
153 1925365
84 46161946
120 19515674
140 39567667
18
36 6939854
219 19270307
107 26811080
135 44704863
1...

output:

32896
15420
32896
59110
32896
54741
59110
1
32896
32896
32896
1
32896
15420
32896
32896
0
32896
15420
32896
15420
32896
32896
32896
32896
21846
32896
32896
54741
54741
59110
32896
32896
32896
32896
32896
32896
32896
54741
54741
32896
43690
32896
32896
32896
32896
17476
32896
59110
15420
32896
59110
...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 4132kb

input:

100
162
143 1143808
192 3810724
189 1037339
105 270668
167 1068188
216 4408992
225 1618501
221 430240
120 3189057
223 2722065
217 1793649
29 3122166
129 249284
245 4125250
89 317643
254 3504072
170 4904459
104 2478836
240 1440277
180 3705854
255 3406356
149 1736411
33 4267429
227 2649591
78 4076525
...

output:

32896
32896
32896
54741
54741
32896
32896
59110
32896
32896
59110
54741
17476
32896
32896
59110
32896
32896
54741
32896
32896
54741
32896
54741
32896
17476
15420
32896
54741
54741
54741
54741
39321
32896
59110
59110
54741
59110
32896
32896
54741
32896
32896
32896
32896
32896
54741
0
32896
54741
1542...

result:

ok 100 numbers

Test #7:

score: 0
Accepted
time: 5ms
memory: 4116kb

input:

100
2
225 103463954
133 98673573
1
115 229035681
2
72 99532710
56 262010873
1
29 163503969
3
209 190760315
244 3444017
50 194052768
1
64 90518604
3
133 254936162
112 248946806
219 174695931
1
237 93137417
3
151 238090677
19 2534188
145 26960475
3
224 159486758
106 47651522
179 262824676
1
250 540564...

output:

54741
48060
32896
21846
54741
54741
32896
21846
32896
32896
48060
32896
39321
32896
32896
32896
54741
54741
32896
48060
59110
17476
32896
15420
32896
26215
15420
0
32896
32896
15420
32896
32896
32896
54741
54741
48060
15420
15420
59110
32896
32896
32896
32896
32896
54741
21846
32896
54741
1
32896
59...

result:

ok 100 numbers

Test #8:

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

input:

100
5
9 31874638
121 25059072
79 135500659
252 5862068
235 95284441
5
93 4009689
251 85715731
161 161993061
85 174911893
33 146760588
5
47 131530698
22 19994334
98 99702159
196 78068211
176 86704392
5
116 34106857
39 148267518
79 165442900
16 114763590
0 161252155
5
174 193371329
124 109104737
185 1...

output:

32896
54741
54741
54741
54741
32896
54741
32896
32896
17476
54741
59110
32896
54741
1
54741
54741
15420
43690
1
32896
32896
39321
32896
21846
32896
32896
54741
32896
54741
32896
32896
15420
32896
43690
15420
32896
54741
32896
32896
59110
54741
39321
54741
54741
32896
54741
32896
54741
32896
32896
59...

result:

ok 100 numbers

Test #9:

score: 0
Accepted
time: 5ms
memory: 3812kb

input:

100
33
44 18869789
117 8369510
145 3544065
144 3664765
168 1365372
85 12860320
150 13537400
53 8130861
91 4951044
63 8583660
110 17817008
94 4597127
255 7812378
14 17438008
129 16276681
186 5448132
2 11721273
74 6179751
181 10738486
49 19672464
98 19560557
190 14484751
225 5605695
135 9185676
156 92...

output:

32896
32896
54741
17476
59110
32896
32896
32896
59110
59110
32896
54741
32896
32896
32896
32896
32896
32896
54741
32896
32896
59110
54741
54741
32896
21846
54741
54741
32896
54741
43690
32896
32896
32896
32896
32896
17476
32896
32896
54741
32896
54741
32896
59110
59110
32896
32896
32896
32896
32896
...

result:

ok 100 numbers

Test #10:

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

input:

100
9
113 24641456
211 94030371
136 79996041
181 26478413
180 4010900
84 17453960
5 68850072
112 80595759
207 98062006
5
12 37702784
80 70203355
154 27068043
195 8627370
224 36311167
4
86 89385424
124 55291852
174 21271530
52 37177714
5
153 62356676
6 31133088
249 54379427
158 58660757
17 71472808
2...

output:

54741
32896
59110
54741
54741
32896
54741
32896
6426
32896
32896
54741
32896
32896
32896
54741
39321
54741
54741
32896
54741
32896
59110
54741
17476
54741
54741
59110
43690
32896
32896
32896
54741
32896
32896
32896
54741
39321
32896
39321
54741
54741
32896
32896
54741
32896
21846
32896
17476
32896
3...

result:

ok 100 numbers

Test #11:

score: 0
Accepted
time: 5ms
memory: 3836kb

input:

100
49
144 4682405
99 6524578
55 7445296
28 7539543
113 6780302
169 3932842
214 4675084
245 3630237
87 5943524
15 6686127
29 5394734
211 6289135
146 4999318
152 7976657
115 6464846
217 3716932
104 2332998
75 669827
89 1437466
160 9175851
8 3009996
17 4165901
98 7340466
158 9527493
106 6171697
90 754...

output:

54741
54741
54741
54741
32896
32896
54741
32896
32896
54741
17476
32896
32896
54741
32896
32896
59110
32896
59110
32896
59110
32896
59110
54741
32896
32896
59110
32896
59110
54741
54741
32896
32896
32896
32896
32896
54741
32896
59110
32896
32896
32896
32896
32896
32896
32896
59110
54741
32896
32896
...

result:

ok 100 numbers

Test #12:

score: 0
Accepted
time: 9ms
memory: 6152kb

input:

100
1
223 1
1
21 1
1
192 1
1
239 1
1
167 1
1
137 1
1
99 1
1
164 1
1
84 1
1
189 1
1
184 1
1
166 1
1
242 1
1
112 1
1
112 1
1
244 1
1
49 1
1
127 1
1
22 1
1
58 1
1
152 1
1
49 1
1
221 1
1
61 1
1
228 1
1
29 1
1
217 1
1
136 1
1
87 1
1
72 1
1
167 1
1
123 1
1
42 1
1
178 1
1
116 1
1
193 1
1
85 1
1
178 1
1
61 ...

output:

223
21
192
239
167
137
99
164
84
189
184
166
242
112
112
244
49
127
22
58
152
49
221
61
228
29
217
136
87
72
167
123
42
178
116
193
85
178
61
163
245
147
153
99
168
5
173
17
156
106
182
109
238
122
229
93
156
121
88
5
50
233
104
127
229
122
123
55
198
185
127
29
27
101
106
142
82
113
159
198
185
64
...

result:

ok 100 numbers

Test #13:

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

input:

100
2
212 2
156 1
2
97 1
251 2
1
8 1
1
98 2
2
198 2
29 1
2
94 1
50 2
2
252 2
9 1
1
48 2
2
17 1
42 2
2
86 2
71 1
2
180 2
141 2
1
83 2
1
13 2
2
201 1
112 2
2
182 1
174 1
1
104 2
2
141 1
109 1
1
56 2
2
103 2
253 2
1
65 1
1
59 1
2
4 2
14 1
1
187 1
1
148 1
2
245 2
240 1
1
211 1
2
145 2
243 1
1
37 1
2
29 ...

output:

2665
11236
8
21331
30940
47881
26994
4626
28561
49149
54741
2056
21331
49555
41056
54484
35470
39064
32896
65
59
60454
187
148
18565
211
54799
37
20935
47089
39835
3000
21331
17611
22374
9601
51366
32896
148
4369
216
39064
28270
40411
1260
21331
52495
128
56461
186
15420
12601
76
28270
55501
43165
6...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 17ms
memory: 5960kb

input:

100
2
5 2
24 2
2
51 3
171 3
1
154 3
3
7 3
98 1
232 1
3
87 1
95 1
185 1
1
190 1
3
11 3
77 1
253 1
3
242 2
1 2
247 2
3
152 2
252 2
209 1
3
86 1
223 1
230 3
2
193 2
153 3
2
243 2
196 2
1
39 2
1
98 2
1
193 1
3
175 1
128 3
149 2
3
80 2
236 2
186 3
3
155 3
179 1
6 2
2
110 2
141 2
2
118 2
124 2
3
61 2
120 ...

output:

2056
39441
50199
6561
11824
190
35631
59110
35631
59076
59635
2056
60909
21331
193
15556
44200
48196
32896
32896
26470
39321
125
33916
21846
26215
58566
39064
65289
5
39000
6546
32896
34
160
59076
147
11454
28270
50406
39441
2056
53551
15930
39771
71
58821
25770
61201
15556
39064
28
9154
50661
12850...

result:

ok 100 numbers

Test #15:

score: -100
Wrong Answer
time: 73ms
memory: 6204kb

input:

100
4
36 2
119 1
46 1
213 2
4
127 1
176 1
17 3
156 2
3
103 3
7 3
125 2
3
197 2
207 3
65 1
2
178 3
220 1
3
88 2
39 3
195 2
3
145 2
185 4
222 3
1
54 3
2
131 1
81 4
4
156 1
121 3
222 1
8 1
2
225 1
200 2
3
97 3
119 3
43 4
2
225 1
44 2
1
95 4
4
132 3
115 2
125 1
128 2
3
63 1
220 3
174 2
3
251 3
58 3
139 ...

output:

39576
50661
26470
23580
1036
256
34936
20064
2245
41056
8125
26470
61294
28270
1
8721
22101
41056
15420
32896
54741
256
49216
2056
39321
16576
8026
30856
12850
59110
54741
15420
2056
32896
26470
54741
26470
28
60711
23901
21846
32896
63496
8224
59620
256
48196
52701
59110
48060
52701
32571
32896
101...

result:

wrong answer 32nd numbers differ - expected: '48060', found: '15420'