# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20746 |
2017-02-15T08:03:27 Z |
ainu7 |
복불복 (OJUZ11_luck) |
C++11 |
|
533 ms |
2024 KB |
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
const int mmod = 1000000007;
int calc(vector<int> a, vector<int> b, int k, int ue, int le) {
int n = a.size();
vector<int> cnt(n);
for (int i=0; i<k; i++)
for (int j=0; j<n; j++)
if (a[i]+b[j] >= ue) cnt[i] = j+1;
for (int i=k; i<n; i++)
for (int j=0; j<n; j++)
if (a[i]+b[j] > le) cnt[i] = j+1;
vector<int> prv(n+1);
prv[0] = 1;
if (k % 2) prv[0] = -1;
for (int i=n-1; i>=0; i--) {
vector<int> nxt(n+1);
for (int j=0; j<n; j++) {
int mult = max(0, cnt[i] - j);
nxt[j+1] = (nxt[j+1] - 1LL * mult * prv[j]) % mmod;
if (i >= k) {
nxt[j] = (nxt[j] + prv[j]) % mmod;
}
}
for (int j=0; j<=n; j++)
prv[j] = (nxt[j] + mmod) % mmod;
}
int ret = 0;
for (int i=0; i<=n; i++) {
int now = prv[i];
for (int j=1; j<=n-i; j++)
now = (now * 1LL * j) % mmod;
ret = (ret + now) % mmod;
}
return ret;
}
int main()
{
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i=0; i<n; i++) cin >> a[i];
for (int i=0; i<n; i++) cin >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
int res = 0;
for (int x = 1; x <= 2000; x++) {
res += calc(a, b, k, x, x);
res -= calc(a, b, k, x+1, x);
res %= mmod;
res = (res + mmod) % mmod;
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2024 KB |
Output is correct |
2 |
Correct |
6 ms |
2024 KB |
Output is correct |
3 |
Correct |
3 ms |
2024 KB |
Output is correct |
4 |
Correct |
6 ms |
2024 KB |
Output is correct |
5 |
Correct |
3 ms |
2024 KB |
Output is correct |
6 |
Correct |
3 ms |
2024 KB |
Output is correct |
7 |
Correct |
3 ms |
2024 KB |
Output is correct |
8 |
Correct |
3 ms |
2024 KB |
Output is correct |
9 |
Correct |
3 ms |
2024 KB |
Output is correct |
10 |
Correct |
3 ms |
2024 KB |
Output is correct |
11 |
Correct |
3 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
0 ms |
2024 KB |
Output is correct |
14 |
Correct |
0 ms |
2024 KB |
Output is correct |
15 |
Correct |
0 ms |
2024 KB |
Output is correct |
16 |
Correct |
3 ms |
2024 KB |
Output is correct |
17 |
Correct |
3 ms |
2024 KB |
Output is correct |
18 |
Correct |
3 ms |
2024 KB |
Output is correct |
19 |
Correct |
3 ms |
2024 KB |
Output is correct |
20 |
Correct |
3 ms |
2024 KB |
Output is correct |
21 |
Correct |
3 ms |
2024 KB |
Output is correct |
22 |
Correct |
3 ms |
2024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
2024 KB |
Output is correct |
2 |
Correct |
516 ms |
2024 KB |
Output is correct |
3 |
Correct |
509 ms |
2024 KB |
Output is correct |
4 |
Correct |
519 ms |
2024 KB |
Output is correct |
5 |
Correct |
509 ms |
2024 KB |
Output is correct |
6 |
Correct |
409 ms |
2024 KB |
Output is correct |
7 |
Correct |
513 ms |
2024 KB |
Output is correct |
8 |
Correct |
13 ms |
2024 KB |
Output is correct |
9 |
Correct |
19 ms |
2024 KB |
Output is correct |
10 |
Correct |
0 ms |
2024 KB |
Output is correct |
11 |
Correct |
0 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
0 ms |
2024 KB |
Output is correct |
14 |
Correct |
263 ms |
2024 KB |
Output is correct |
15 |
Correct |
93 ms |
2024 KB |
Output is correct |
16 |
Correct |
503 ms |
2024 KB |
Output is correct |
17 |
Correct |
516 ms |
2024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2024 KB |
Output is correct |
2 |
Correct |
6 ms |
2024 KB |
Output is correct |
3 |
Correct |
3 ms |
2024 KB |
Output is correct |
4 |
Correct |
6 ms |
2024 KB |
Output is correct |
5 |
Correct |
3 ms |
2024 KB |
Output is correct |
6 |
Correct |
3 ms |
2024 KB |
Output is correct |
7 |
Correct |
3 ms |
2024 KB |
Output is correct |
8 |
Correct |
3 ms |
2024 KB |
Output is correct |
9 |
Correct |
3 ms |
2024 KB |
Output is correct |
10 |
Correct |
3 ms |
2024 KB |
Output is correct |
11 |
Correct |
3 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
0 ms |
2024 KB |
Output is correct |
14 |
Correct |
0 ms |
2024 KB |
Output is correct |
15 |
Correct |
0 ms |
2024 KB |
Output is correct |
16 |
Correct |
3 ms |
2024 KB |
Output is correct |
17 |
Correct |
3 ms |
2024 KB |
Output is correct |
18 |
Correct |
3 ms |
2024 KB |
Output is correct |
19 |
Correct |
3 ms |
2024 KB |
Output is correct |
20 |
Correct |
3 ms |
2024 KB |
Output is correct |
21 |
Correct |
3 ms |
2024 KB |
Output is correct |
22 |
Correct |
3 ms |
2024 KB |
Output is correct |
23 |
Correct |
13 ms |
2024 KB |
Output is correct |
24 |
Correct |
9 ms |
2024 KB |
Output is correct |
25 |
Correct |
13 ms |
2024 KB |
Output is correct |
26 |
Correct |
13 ms |
2024 KB |
Output is correct |
27 |
Correct |
13 ms |
2024 KB |
Output is correct |
28 |
Correct |
13 ms |
2024 KB |
Output is correct |
29 |
Correct |
13 ms |
2024 KB |
Output is correct |
30 |
Correct |
9 ms |
2024 KB |
Output is correct |
31 |
Correct |
9 ms |
2024 KB |
Output is correct |
32 |
Correct |
13 ms |
2024 KB |
Output is correct |
33 |
Correct |
9 ms |
2024 KB |
Output is correct |
34 |
Correct |
9 ms |
2024 KB |
Output is correct |
35 |
Correct |
9 ms |
2024 KB |
Output is correct |
36 |
Correct |
9 ms |
2024 KB |
Output is correct |
37 |
Correct |
9 ms |
2024 KB |
Output is correct |
38 |
Correct |
9 ms |
2024 KB |
Output is correct |
39 |
Correct |
6 ms |
2024 KB |
Output is correct |
40 |
Correct |
13 ms |
2024 KB |
Output is correct |
41 |
Correct |
6 ms |
2024 KB |
Output is correct |
42 |
Correct |
3 ms |
2024 KB |
Output is correct |
43 |
Correct |
3 ms |
2024 KB |
Output is correct |
44 |
Correct |
13 ms |
2024 KB |
Output is correct |
45 |
Correct |
13 ms |
2024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2024 KB |
Output is correct |
2 |
Correct |
6 ms |
2024 KB |
Output is correct |
3 |
Correct |
3 ms |
2024 KB |
Output is correct |
4 |
Correct |
6 ms |
2024 KB |
Output is correct |
5 |
Correct |
3 ms |
2024 KB |
Output is correct |
6 |
Correct |
3 ms |
2024 KB |
Output is correct |
7 |
Correct |
3 ms |
2024 KB |
Output is correct |
8 |
Correct |
3 ms |
2024 KB |
Output is correct |
9 |
Correct |
3 ms |
2024 KB |
Output is correct |
10 |
Correct |
3 ms |
2024 KB |
Output is correct |
11 |
Correct |
3 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
0 ms |
2024 KB |
Output is correct |
14 |
Correct |
0 ms |
2024 KB |
Output is correct |
15 |
Correct |
0 ms |
2024 KB |
Output is correct |
16 |
Correct |
3 ms |
2024 KB |
Output is correct |
17 |
Correct |
3 ms |
2024 KB |
Output is correct |
18 |
Correct |
3 ms |
2024 KB |
Output is correct |
19 |
Correct |
3 ms |
2024 KB |
Output is correct |
20 |
Correct |
3 ms |
2024 KB |
Output is correct |
21 |
Correct |
3 ms |
2024 KB |
Output is correct |
22 |
Correct |
3 ms |
2024 KB |
Output is correct |
23 |
Correct |
526 ms |
2024 KB |
Output is correct |
24 |
Correct |
516 ms |
2024 KB |
Output is correct |
25 |
Correct |
509 ms |
2024 KB |
Output is correct |
26 |
Correct |
519 ms |
2024 KB |
Output is correct |
27 |
Correct |
509 ms |
2024 KB |
Output is correct |
28 |
Correct |
409 ms |
2024 KB |
Output is correct |
29 |
Correct |
513 ms |
2024 KB |
Output is correct |
30 |
Correct |
13 ms |
2024 KB |
Output is correct |
31 |
Correct |
19 ms |
2024 KB |
Output is correct |
32 |
Correct |
0 ms |
2024 KB |
Output is correct |
33 |
Correct |
0 ms |
2024 KB |
Output is correct |
34 |
Correct |
0 ms |
2024 KB |
Output is correct |
35 |
Correct |
0 ms |
2024 KB |
Output is correct |
36 |
Correct |
263 ms |
2024 KB |
Output is correct |
37 |
Correct |
93 ms |
2024 KB |
Output is correct |
38 |
Correct |
503 ms |
2024 KB |
Output is correct |
39 |
Correct |
516 ms |
2024 KB |
Output is correct |
40 |
Correct |
506 ms |
2024 KB |
Output is correct |
41 |
Correct |
526 ms |
2024 KB |
Output is correct |
42 |
Correct |
519 ms |
2024 KB |
Output is correct |
43 |
Correct |
523 ms |
2024 KB |
Output is correct |
44 |
Correct |
516 ms |
2024 KB |
Output is correct |
45 |
Correct |
513 ms |
2024 KB |
Output is correct |
46 |
Correct |
513 ms |
2024 KB |
Output is correct |
47 |
Correct |
506 ms |
2024 KB |
Output is correct |
48 |
Correct |
486 ms |
2024 KB |
Output is correct |
49 |
Correct |
493 ms |
2024 KB |
Output is correct |
50 |
Correct |
523 ms |
2024 KB |
Output is correct |
51 |
Correct |
509 ms |
2024 KB |
Output is correct |
52 |
Correct |
529 ms |
2024 KB |
Output is correct |
53 |
Correct |
509 ms |
2024 KB |
Output is correct |
54 |
Correct |
513 ms |
2024 KB |
Output is correct |
55 |
Correct |
129 ms |
2024 KB |
Output is correct |
56 |
Correct |
129 ms |
2024 KB |
Output is correct |
57 |
Correct |
346 ms |
2024 KB |
Output is correct |
58 |
Correct |
509 ms |
2024 KB |
Output is correct |
59 |
Correct |
533 ms |
2024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2024 KB |
Output is correct |
2 |
Correct |
6 ms |
2024 KB |
Output is correct |
3 |
Correct |
3 ms |
2024 KB |
Output is correct |
4 |
Correct |
6 ms |
2024 KB |
Output is correct |
5 |
Correct |
3 ms |
2024 KB |
Output is correct |
6 |
Correct |
3 ms |
2024 KB |
Output is correct |
7 |
Correct |
3 ms |
2024 KB |
Output is correct |
8 |
Correct |
3 ms |
2024 KB |
Output is correct |
9 |
Correct |
3 ms |
2024 KB |
Output is correct |
10 |
Correct |
3 ms |
2024 KB |
Output is correct |
11 |
Correct |
3 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
0 ms |
2024 KB |
Output is correct |
14 |
Correct |
0 ms |
2024 KB |
Output is correct |
15 |
Correct |
0 ms |
2024 KB |
Output is correct |
16 |
Correct |
3 ms |
2024 KB |
Output is correct |
17 |
Correct |
3 ms |
2024 KB |
Output is correct |
18 |
Correct |
3 ms |
2024 KB |
Output is correct |
19 |
Correct |
3 ms |
2024 KB |
Output is correct |
20 |
Correct |
3 ms |
2024 KB |
Output is correct |
21 |
Correct |
3 ms |
2024 KB |
Output is correct |
22 |
Correct |
3 ms |
2024 KB |
Output is correct |
23 |
Correct |
526 ms |
2024 KB |
Output is correct |
24 |
Correct |
516 ms |
2024 KB |
Output is correct |
25 |
Correct |
509 ms |
2024 KB |
Output is correct |
26 |
Correct |
519 ms |
2024 KB |
Output is correct |
27 |
Correct |
509 ms |
2024 KB |
Output is correct |
28 |
Correct |
409 ms |
2024 KB |
Output is correct |
29 |
Correct |
513 ms |
2024 KB |
Output is correct |
30 |
Correct |
13 ms |
2024 KB |
Output is correct |
31 |
Correct |
19 ms |
2024 KB |
Output is correct |
32 |
Correct |
0 ms |
2024 KB |
Output is correct |
33 |
Correct |
0 ms |
2024 KB |
Output is correct |
34 |
Correct |
0 ms |
2024 KB |
Output is correct |
35 |
Correct |
0 ms |
2024 KB |
Output is correct |
36 |
Correct |
263 ms |
2024 KB |
Output is correct |
37 |
Correct |
93 ms |
2024 KB |
Output is correct |
38 |
Correct |
503 ms |
2024 KB |
Output is correct |
39 |
Correct |
516 ms |
2024 KB |
Output is correct |
40 |
Correct |
13 ms |
2024 KB |
Output is correct |
41 |
Correct |
9 ms |
2024 KB |
Output is correct |
42 |
Correct |
13 ms |
2024 KB |
Output is correct |
43 |
Correct |
13 ms |
2024 KB |
Output is correct |
44 |
Correct |
13 ms |
2024 KB |
Output is correct |
45 |
Correct |
13 ms |
2024 KB |
Output is correct |
46 |
Correct |
13 ms |
2024 KB |
Output is correct |
47 |
Correct |
9 ms |
2024 KB |
Output is correct |
48 |
Correct |
9 ms |
2024 KB |
Output is correct |
49 |
Correct |
13 ms |
2024 KB |
Output is correct |
50 |
Correct |
9 ms |
2024 KB |
Output is correct |
51 |
Correct |
9 ms |
2024 KB |
Output is correct |
52 |
Correct |
9 ms |
2024 KB |
Output is correct |
53 |
Correct |
9 ms |
2024 KB |
Output is correct |
54 |
Correct |
9 ms |
2024 KB |
Output is correct |
55 |
Correct |
9 ms |
2024 KB |
Output is correct |
56 |
Correct |
6 ms |
2024 KB |
Output is correct |
57 |
Correct |
13 ms |
2024 KB |
Output is correct |
58 |
Correct |
6 ms |
2024 KB |
Output is correct |
59 |
Correct |
3 ms |
2024 KB |
Output is correct |
60 |
Correct |
3 ms |
2024 KB |
Output is correct |
61 |
Correct |
13 ms |
2024 KB |
Output is correct |
62 |
Correct |
13 ms |
2024 KB |
Output is correct |
63 |
Correct |
506 ms |
2024 KB |
Output is correct |
64 |
Correct |
526 ms |
2024 KB |
Output is correct |
65 |
Correct |
519 ms |
2024 KB |
Output is correct |
66 |
Correct |
523 ms |
2024 KB |
Output is correct |
67 |
Correct |
516 ms |
2024 KB |
Output is correct |
68 |
Correct |
513 ms |
2024 KB |
Output is correct |
69 |
Correct |
513 ms |
2024 KB |
Output is correct |
70 |
Correct |
506 ms |
2024 KB |
Output is correct |
71 |
Correct |
486 ms |
2024 KB |
Output is correct |
72 |
Correct |
493 ms |
2024 KB |
Output is correct |
73 |
Correct |
523 ms |
2024 KB |
Output is correct |
74 |
Correct |
509 ms |
2024 KB |
Output is correct |
75 |
Correct |
529 ms |
2024 KB |
Output is correct |
76 |
Correct |
509 ms |
2024 KB |
Output is correct |
77 |
Correct |
513 ms |
2024 KB |
Output is correct |
78 |
Correct |
129 ms |
2024 KB |
Output is correct |
79 |
Correct |
129 ms |
2024 KB |
Output is correct |
80 |
Correct |
346 ms |
2024 KB |
Output is correct |
81 |
Correct |
509 ms |
2024 KB |
Output is correct |
82 |
Correct |
533 ms |
2024 KB |
Output is correct |
83 |
Correct |
439 ms |
2024 KB |
Output is correct |
84 |
Correct |
276 ms |
2024 KB |
Output is correct |
85 |
Correct |
439 ms |
2024 KB |
Output is correct |
86 |
Correct |
436 ms |
2024 KB |
Output is correct |
87 |
Correct |
443 ms |
2024 KB |
Output is correct |
88 |
Correct |
453 ms |
2024 KB |
Output is correct |
89 |
Correct |
443 ms |
2024 KB |
Output is correct |
90 |
Correct |
513 ms |
2024 KB |
Output is correct |
91 |
Correct |
503 ms |
2024 KB |
Output is correct |
92 |
Correct |
13 ms |
2024 KB |
Output is correct |
93 |
Correct |
496 ms |
2024 KB |
Output is correct |
94 |
Correct |
483 ms |
2024 KB |
Output is correct |
95 |
Correct |
476 ms |
2024 KB |
Output is correct |
96 |
Correct |
463 ms |
2024 KB |
Output is correct |
97 |
Correct |
483 ms |
2024 KB |
Output is correct |
98 |
Correct |
479 ms |
2024 KB |
Output is correct |
99 |
Correct |
13 ms |
2024 KB |
Output is correct |
100 |
Correct |
139 ms |
2024 KB |
Output is correct |
101 |
Correct |
496 ms |
2024 KB |
Output is correct |
102 |
Correct |
479 ms |
2024 KB |
Output is correct |
103 |
Correct |
473 ms |
2024 KB |
Output is correct |
104 |
Correct |
446 ms |
2024 KB |
Output is correct |
105 |
Correct |
469 ms |
2024 KB |
Output is correct |
106 |
Correct |
356 ms |
2024 KB |
Output is correct |
107 |
Correct |
493 ms |
2024 KB |
Output is correct |