QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509797#5697. 萨菲克斯·阿瑞A_programmer55 666ms7668kbC++171.4kb2024-08-08 18:46:572024-08-08 18:46:57

Judging History

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

  • [2024-08-08 18:46:57]
  • 评测
  • 测评结果:55
  • 用时:666ms
  • 内存:7668kb
  • [2024-08-08 18:46:57]
  • 提交

answer

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

typedef long long ll;
const ll mod = 1e9 + 7;

ll fpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int c[505];
ll fac, ifac[505];
ll f[505][505], pre[505][505];

inline void chkadd(ll &x, ll y) { ((x += y) >= mod) && (x -= mod); (x < 0) && (x += mod); }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m; cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> c[i];
    fac = 1; for (int i = 1; i <= n; i++) (fac *= i) %= mod;
    ifac[n] = fpow(fac, mod - 2); for (int i = n - 1; ~i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;

    f[0][0] = 1;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++) pre[i][j] = f[i][j];
        for (int k = i + 1; k <= n; k++)
        {
            pre[k][0] = pre[k - 1][0];
            for (int j = 1; j <= m; j++) chkadd(pre[k][j] = pre[k - 1][j], (k >= c[j] ? pre[k - c[j]][j - 1] : 0) - pre[k - 1][j - 1]);
            for (int j = 1; j <= m; j++) chkadd(f[k][j], (pre[k - 1][j - 1] + mod - (k > c[j] ? pre[k - c[j] - 1][j - 1] : 0)) * ifac[k - i] % mod);
        }
        for (int k = i; k <= n; k++) memset(pre[k], 0, sizeof(pre[k]));
    }

    ll ans = 0; for (int i = 0; i <= m; i++) chkadd(ans, f[n][i]);
    cout << ans * fac % mod;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 1ms
memory: 5704kb

input:

6 3
2 3 4

output:

270

result:

ok 1 number(s): "270"

Test #2:

score: 5
Accepted
time: 1ms
memory: 5652kb

input:

10 7
1 3 4 2 8 4 4

output:

3395650

result:

ok 1 number(s): "3395650"

Test #3:

score: 5
Accepted
time: 1ms
memory: 5672kb

input:

10 7
5 2 4 7 2 9 9

output:

3521671

result:

ok 1 number(s): "3521671"

Test #4:

score: 5
Accepted
time: 12ms
memory: 7484kb

input:

490 2
397 150

output:

156076820

result:

ok 1 number(s): "156076820"

Test #5:

score: 5
Accepted
time: 14ms
memory: 7668kb

input:

499 3
365 104 84

output:

359276756

result:

ok 1 number(s): "359276756"

Test #6:

score: 5
Accepted
time: 261ms
memory: 7568kb

input:

495 181
495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 ...

output:

367030087

result:

ok 1 number(s): "367030087"

Test #7:

score: 5
Accepted
time: 257ms
memory: 7536kb

input:

497 174
497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 ...

output:

842700950

result:

ok 1 number(s): "842700950"

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 5940kb

input:

47 37
24
47
34
37
32
25
42
33
27
47
47
23
35
46
41
27
2
0
2
3
0
2
4
0
2
1
2
1
4
1
3
44
44
35
25
24
26

output:

826475347

result:

wrong answer 1st numbers differ - expected: '997241548', found: '826475347'

Test #9:

score: 5
Accepted
time: 1ms
memory: 5884kb

input:

50 33
44
32
32
31
40
38
37
35
29
29
30
25
40
45
36
46
36
4
1
2
1
2
3
5
5
5
4
3
4
2
5
3
29

output:

985463988

result:

ok 1 number(s): "985463988"

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 5860kb

input:

45 35
40
28
26
34
3
4
1
4
2
1
4
2
4
4
4
3
0
1
1
37
22
33
23
30
39
39
30
39
44
31
29
38
44
39
23

output:

870483221

result:

wrong answer 1st numbers differ - expected: '246027250', found: '870483221'

Test #11:

score: 0
Wrong Answer
time: 42ms
memory: 6444kb

input:

192 149
123
184
177
147
156
148
141
158
185
172
100
150
134
157
156
127
140
128
130
156
139
130
105
172
162
119
122
174
166
189
107
189
104
172
168
163
99
100
113
188
176
157
139
167
166
185
143
105
148
130
187
115
145
163
140
186
145
139
185
166
161
178
185
124
153
182
191
174
136
133
170
106
154
1...

output:

412216700

result:

wrong answer 1st numbers differ - expected: '18950292', found: '412216700'

Test #12:

score: 0
Wrong Answer
time: 40ms
memory: 6468kb

input:

199 145
176
134
152
179
103
162
197
126
112
100
173
106
177
165
173
148
189
180
157
175
132
105
180
190
190
120
152
130
196
193
147
194
121
159
118
145
149
149
145
171
171
194
151
193
187
107
132
189
185
146
139
130
179
155
180
171
157
104
171
101
119
189
120
165
124
136
163
150
196
195
161
187
128
...

output:

437944805

result:

wrong answer 1st numbers differ - expected: '211123272', found: '437944805'

Test #13:

score: 0
Wrong Answer
time: 41ms
memory: 6536kb

input:

198 153
124
132
193
111
184
197
150
163
195
169
99
162
112
153
169
165
183
175
136
192
161
171
180
12
19
2
17
9
11
18
0
12
17
4
2
12
9
7
109
181
1
13
7
16
9
5
5
12
12
16
6
10
6
15
5
102
113
101
126
157
177
189
191
134
124
145
126
170
144
122
192
110
161
183
196
167
127
161
150
188
188
111
158
194
18...

output:

107162536

result:

wrong answer 1st numbers differ - expected: '921172591', found: '107162536'

Test #14:

score: 0
Wrong Answer
time: 39ms
memory: 6416kb

input:

191 159
133
115
96
114
146
165
138
121
124
100
164
188
138
142
150
115
137
139
186
164
149
109
191
145
140
120
125
162
142
191
101
155
117
150
182
184
186
137
97
120
173
177
120
100
168
182
110
115
174
96
150
162
127
133
181
155
176
188
183
167
125
163
172
125
124
105
149
172
163
179
119
149
147
106...

output:

505136405

result:

wrong answer 1st numbers differ - expected: '174115008', found: '505136405'

Test #15:

score: 5
Accepted
time: 666ms
memory: 7540kb

input:

486 391
416
380
330
466
464
404
405
399
345
362
440
413
461
469
442
250
379
281
333
376
417
453
470
450
353
324
427
323
345
293
378
373
470
328
420
408
374
373
248
470
286
328
457
276
444
474
466
328
322
456
435
420
12
26
25
16
35
35
35
5
42
3
23
15
7
17
21
479
381
401
289
463
339
289
374
332
275
33...

output:

61471107

result:

ok 1 number(s): "61471107"

Test #16:

score: 0
Wrong Answer
time: 590ms
memory: 7528kb

input:

482 370
455
359
363
398
476
318
462
466
476
41
7
1
5
6
28
35
16
35
12
19
31
16
37
11
261
312
473
281
269
334
378
461
453
246
266
430
470
281
407
251
280
268
334
344
254
437
328
316
287
314
357
423
466
341
360
299
465
297
450
351
261
329
408
481
340
433
254
265
395
282
383
383
295
455
375
398
328
309...

output:

319372751

result:

wrong answer 1st numbers differ - expected: '656550309', found: '319372751'

Test #17:

score: 5
Accepted
time: 566ms
memory: 7496kb

input:

486 363
344
293
362
446
364
332
289
413
249
462
261
401
461
253
295
439
358
395
457
269
457
321
366
332
282
384
322
243
282
295
252
448
389
483
486
398
261
435
443
351
331
432
317
442
354
244
305
293
386
443
316
371
329
349
360
364
363
442
411
450
306
458
444
372
384
382
430
323
348
352
378
262
321
...

output:

819792353

result:

ok 1 number(s): "819792353"

Test #18:

score: 0
Wrong Answer
time: 575ms
memory: 7508kb

input:

481 357
242
301
426
437
334
292
366
256
342
310
407
247
424
375
284
276
354
432
288
268
324
463
405
369
413
354
421
366
363
383
343
278
331
358
390
425
310
455
453
321
367
372
352
315
473
259
373
424
270
476
310
382
384
264
394
448
275
414
31
43
38
22
18
45
11
5
35
22
44
13
12
30
25
437
445
429
478
...

output:

572255472

result:

wrong answer 1st numbers differ - expected: '402601428', found: '572255472'

Test #19:

score: 0
Wrong Answer
time: 643ms
memory: 7596kb

input:

480 383
364
323
402
326
358
360
242
400
448
401
284
265
383
270
426
267
355
375
308
416
334
246
280
344
374
242
324
306
332
454
263
435
287
326
359
267
290
445
369
255
392
381
298
383
428
280
417
419
308
364
415
314
28
2
25
5
37
12
4
31
39
39
32
36
47
9
39
334
404
285
433
424
434
298
404
300
423
344...

output:

354746491

result:

wrong answer 1st numbers differ - expected: '873285991', found: '354746491'

Test #20:

score: 5
Accepted
time: 568ms
memory: 7452kb

input:

481 367
303
420
425
352
405
426
292
296
250
308
276
375
341
317
384
316
351
471
403
371
244
449
324
343
392
340
454
333
481
480
393
390
283
431
365
396
423
396
371
385
442
247
475
256
270
391
464
432
249
339
356
280
304
251
327
316
423
362
249
363
440
441
308
340
365
34
29
31
42
22
31
40
8
27
6
5
27...

output:

854884498

result:

ok 1 number(s): "854884498"