# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20339 | 2017-02-07T04:56:39 Z | admin | 복불복 (OJUZ11_luck) | C++11 | 174 ms | 2292 KB |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <deque> #include <utility> #include <bitset> #include <limits.h> #include <time.h> #include <functional> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long llu; typedef double lf; typedef unsigned int uint; typedef long double llf; typedef pair<int, int> pii; typedef pair<ll, int> pli; #define debug(format, ...) printf(format, __VA_ARGS__); const int N_ = 350; const int MOD = (int)1e9 + 7; int N, K; int A[N_], B[N_]; int comb[N_][N_]; int fac[N_]; struct mint { ll val; mint() { val = 0; } mint(ll val): val(val % MOD) { val = 0; } ~mint() { } ll& operator*() { return val;} mint operator+ (mint t) { return val + t.val; } mint operator- (mint t) { return val - t.val + MOD; } mint operator* (mint t) { return val * t.val; } mint operator+= (mint t) { return *this = (val + t.val); } mint operator-= (mint t) { return *this = (val - t.val); } }; int bound[N_]; mint ta[N_][N_]; mint tb[N_][N_]; int ha[N_]; ll nat (ll x) { return (x < 0) ? 0 : x; } mint count_cases (int L, int R) { mint ret = 0; // bound 구하기 for(int i = K, cur = 1; i > 0; i--) { while(cur <= N && B[cur] <= L - A[i]) cur += 1; if(cur == 1) return 0; bound[i] = cur - 1; } for(int i = K+1, cur = N; i <= N; i++) { while(cur > 0 && B[cur] >= R - A[i]) cur -= 1; if(cur == N) return 0; bound[i] = cur + 1; } // prep for(int j = 1; j <= N; j++) { ha[j] = 0; for(int i = 1; i <= K; i++) if(j <= bound[i]) ha[j] += 1; } for(int k = 0; k <= K; k++) { // ta fill(ta[k], ta[k] + N + 2, 0); if(k == 0) { for(int j = 1; j <= N+1; j++) ta[k][j] = 1; }else { for(int j = N+1; j >= bound[K+1]; j--) { ta[k][j] = ta[k][j+1]; if(ha[j] >= k) ta[k][j] += ta[k-1][j+1] * nat(ha[j] - k + 1); } } tb[K][K-k] = ta[k][bound[K+1]] * fac[K-k]; } for(int i = K+1; i <= N; i++) { int d = (i == K+1) ? 0 : (bound[i-1] - bound[i]); for(int c = 0; c <= K; c++) { tb[i][c] = 0; for(int z = 0; z <= d && c+z <= K; z++) tb[i][c] += tb[i-1][c+z] * comb[d][z] * nat((N - bound[i] + 1) - (i-1-c)); } } for(int z = 0; z <= bound[N]-1 && z <= K; z++) ret += tb[N][z] * comb[bound[N]-1][z]; return ret; } /* 서브태스크 */ // 1. n <= 8 (n!) -O // 2. n <= 100, k = 1 (n) -X // 3. n <= 15 (n^3 2^n) // 4. k <= 8 (n^3 k^2) // 5. n <= 100 (n^3 k) -O int main() { scanf("%d%d", &N, &K); for(int i = 1; i <= N; i++) scanf("%d", A+i); for(int i = 1; i <= N; i++) scanf("%d", B+i); sort(A+1, A+N+1, greater<int>()); sort(B+1, B+N+1, greater<int>()); for(int i = N; i > 0; i--) A[i] = A[1] - A[i], B[i] = B[1] - B[i]; // nCr comb[0][0] = 1; for(int i = 1; i <= N; i++) { comb[i][0] = comb[i][i] = 1; for(int j = 1; j < i; j++) comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % MOD; } fac[0] = 1; for(int i = 1; i <= N; i++) fac[i] = ((ll)fac[i-1] * i) % MOD; if(N == K) return 0 & printf("%d\n", fac[N]); mint ans = 0; for(int X = A[K] + B[1]; X <= A[N] + B[N]; X++) { ans += count_cases(X, X) - count_cases(X-1, X); } printf("%lld\n", *ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2040 KB | Output is correct |
2 | Correct | 5 ms | 2176 KB | Output is correct |
3 | Correct | 5 ms | 2176 KB | Output is correct |
4 | Correct | 3 ms | 2176 KB | Output is correct |
5 | Correct | 4 ms | 2176 KB | Output is correct |
6 | Correct | 4 ms | 2176 KB | Output is correct |
7 | Correct | 4 ms | 2176 KB | Output is correct |
8 | Correct | 5 ms | 2176 KB | Output is correct |
9 | Correct | 4 ms | 2176 KB | Output is correct |
10 | Correct | 4 ms | 2176 KB | Output is correct |
11 | Correct | 3 ms | 2228 KB | Output is correct |
12 | Correct | 3 ms | 2228 KB | Output is correct |
13 | Correct | 3 ms | 2228 KB | Output is correct |
14 | Correct | 3 ms | 2228 KB | Output is correct |
15 | Correct | 3 ms | 2228 KB | Output is correct |
16 | Correct | 4 ms | 2228 KB | Output is correct |
17 | Correct | 4 ms | 2228 KB | Output is correct |
18 | Correct | 4 ms | 2228 KB | Output is correct |
19 | Correct | 4 ms | 2228 KB | Output is correct |
20 | Correct | 3 ms | 2228 KB | Output is correct |
21 | Correct | 3 ms | 2228 KB | Output is correct |
22 | Correct | 4 ms | 2228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2288 KB | Output is correct |
2 | Correct | 4 ms | 2292 KB | Output is correct |
3 | Correct | 4 ms | 2292 KB | Output is correct |
4 | Correct | 5 ms | 2292 KB | Output is correct |
5 | Correct | 6 ms | 2292 KB | Output is correct |
6 | Correct | 7 ms | 2292 KB | Output is correct |
7 | Correct | 8 ms | 2292 KB | Output is correct |
8 | Correct | 3 ms | 2292 KB | Output is correct |
9 | Correct | 4 ms | 2292 KB | Output is correct |
10 | Correct | 3 ms | 2292 KB | Output is correct |
11 | Correct | 3 ms | 2292 KB | Output is correct |
12 | Correct | 3 ms | 2292 KB | Output is correct |
13 | Correct | 3 ms | 2292 KB | Output is correct |
14 | Correct | 9 ms | 2292 KB | Output is correct |
15 | Correct | 7 ms | 2292 KB | Output is correct |
16 | Correct | 12 ms | 2292 KB | Output is correct |
17 | Correct | 14 ms | 2292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2040 KB | Output is correct |
2 | Correct | 5 ms | 2176 KB | Output is correct |
3 | Correct | 5 ms | 2176 KB | Output is correct |
4 | Correct | 3 ms | 2176 KB | Output is correct |
5 | Correct | 4 ms | 2176 KB | Output is correct |
6 | Correct | 4 ms | 2176 KB | Output is correct |
7 | Correct | 4 ms | 2176 KB | Output is correct |
8 | Correct | 5 ms | 2176 KB | Output is correct |
9 | Correct | 4 ms | 2176 KB | Output is correct |
10 | Correct | 4 ms | 2176 KB | Output is correct |
11 | Correct | 3 ms | 2228 KB | Output is correct |
12 | Correct | 3 ms | 2228 KB | Output is correct |
13 | Correct | 3 ms | 2228 KB | Output is correct |
14 | Correct | 3 ms | 2228 KB | Output is correct |
15 | Correct | 3 ms | 2228 KB | Output is correct |
16 | Correct | 4 ms | 2228 KB | Output is correct |
17 | Correct | 4 ms | 2228 KB | Output is correct |
18 | Correct | 4 ms | 2228 KB | Output is correct |
19 | Correct | 4 ms | 2228 KB | Output is correct |
20 | Correct | 3 ms | 2228 KB | Output is correct |
21 | Correct | 3 ms | 2228 KB | Output is correct |
22 | Correct | 4 ms | 2228 KB | Output is correct |
23 | Correct | 5 ms | 2292 KB | Output is correct |
24 | Correct | 4 ms | 2292 KB | Output is correct |
25 | Correct | 7 ms | 2292 KB | Output is correct |
26 | Correct | 6 ms | 2292 KB | Output is correct |
27 | Correct | 3 ms | 2292 KB | Output is correct |
28 | Correct | 3 ms | 2292 KB | Output is correct |
29 | Correct | 7 ms | 2292 KB | Output is correct |
30 | Correct | 3 ms | 2292 KB | Output is correct |
31 | Correct | 5 ms | 2292 KB | Output is correct |
32 | Correct | 5 ms | 2292 KB | Output is correct |
33 | Correct | 6 ms | 2292 KB | Output is correct |
34 | Correct | 3 ms | 2292 KB | Output is correct |
35 | Correct | 5 ms | 2292 KB | Output is correct |
36 | Correct | 5 ms | 2292 KB | Output is correct |
37 | Correct | 6 ms | 2292 KB | Output is correct |
38 | Correct | 7 ms | 2292 KB | Output is correct |
39 | Correct | 3 ms | 2292 KB | Output is correct |
40 | Correct | 4 ms | 2292 KB | Output is correct |
41 | Correct | 5 ms | 2292 KB | Output is correct |
42 | Correct | 5 ms | 2292 KB | Output is correct |
43 | Correct | 3 ms | 2292 KB | Output is correct |
44 | Correct | 3 ms | 2292 KB | Output is correct |
45 | Correct | 4 ms | 2292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2040 KB | Output is correct |
2 | Correct | 5 ms | 2176 KB | Output is correct |
3 | Correct | 5 ms | 2176 KB | Output is correct |
4 | Correct | 3 ms | 2176 KB | Output is correct |
5 | Correct | 4 ms | 2176 KB | Output is correct |
6 | Correct | 4 ms | 2176 KB | Output is correct |
7 | Correct | 4 ms | 2176 KB | Output is correct |
8 | Correct | 5 ms | 2176 KB | Output is correct |
9 | Correct | 4 ms | 2176 KB | Output is correct |
10 | Correct | 4 ms | 2176 KB | Output is correct |
11 | Correct | 3 ms | 2228 KB | Output is correct |
12 | Correct | 3 ms | 2228 KB | Output is correct |
13 | Correct | 3 ms | 2228 KB | Output is correct |
14 | Correct | 3 ms | 2228 KB | Output is correct |
15 | Correct | 3 ms | 2228 KB | Output is correct |
16 | Correct | 4 ms | 2228 KB | Output is correct |
17 | Correct | 4 ms | 2228 KB | Output is correct |
18 | Correct | 4 ms | 2228 KB | Output is correct |
19 | Correct | 4 ms | 2228 KB | Output is correct |
20 | Correct | 3 ms | 2228 KB | Output is correct |
21 | Correct | 3 ms | 2228 KB | Output is correct |
22 | Correct | 4 ms | 2228 KB | Output is correct |
23 | Correct | 13 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2292 KB | Output is correct |
25 | Correct | 4 ms | 2292 KB | Output is correct |
26 | Correct | 5 ms | 2292 KB | Output is correct |
27 | Correct | 6 ms | 2292 KB | Output is correct |
28 | Correct | 7 ms | 2292 KB | Output is correct |
29 | Correct | 8 ms | 2292 KB | Output is correct |
30 | Correct | 3 ms | 2292 KB | Output is correct |
31 | Correct | 4 ms | 2292 KB | Output is correct |
32 | Correct | 3 ms | 2292 KB | Output is correct |
33 | Correct | 3 ms | 2292 KB | Output is correct |
34 | Correct | 3 ms | 2292 KB | Output is correct |
35 | Correct | 3 ms | 2292 KB | Output is correct |
36 | Correct | 9 ms | 2292 KB | Output is correct |
37 | Correct | 7 ms | 2292 KB | Output is correct |
38 | Correct | 12 ms | 2292 KB | Output is correct |
39 | Correct | 14 ms | 2292 KB | Output is correct |
40 | Correct | 5 ms | 2292 KB | Output is correct |
41 | Correct | 4 ms | 2292 KB | Output is correct |
42 | Correct | 7 ms | 2292 KB | Output is correct |
43 | Correct | 6 ms | 2292 KB | Output is correct |
44 | Correct | 3 ms | 2292 KB | Output is correct |
45 | Correct | 3 ms | 2292 KB | Output is correct |
46 | Correct | 7 ms | 2292 KB | Output is correct |
47 | Correct | 3 ms | 2292 KB | Output is correct |
48 | Correct | 5 ms | 2292 KB | Output is correct |
49 | Correct | 5 ms | 2292 KB | Output is correct |
50 | Correct | 6 ms | 2292 KB | Output is correct |
51 | Correct | 3 ms | 2292 KB | Output is correct |
52 | Correct | 5 ms | 2292 KB | Output is correct |
53 | Correct | 5 ms | 2292 KB | Output is correct |
54 | Correct | 6 ms | 2292 KB | Output is correct |
55 | Correct | 7 ms | 2292 KB | Output is correct |
56 | Correct | 3 ms | 2292 KB | Output is correct |
57 | Correct | 4 ms | 2292 KB | Output is correct |
58 | Correct | 5 ms | 2292 KB | Output is correct |
59 | Correct | 5 ms | 2292 KB | Output is correct |
60 | Correct | 3 ms | 2292 KB | Output is correct |
61 | Correct | 3 ms | 2292 KB | Output is correct |
62 | Correct | 4 ms | 2292 KB | Output is correct |
63 | Correct | 41 ms | 2292 KB | Output is correct |
64 | Correct | 7 ms | 2292 KB | Output is correct |
65 | Correct | 7 ms | 2292 KB | Output is correct |
66 | Correct | 40 ms | 2292 KB | Output is correct |
67 | Correct | 46 ms | 2292 KB | Output is correct |
68 | Correct | 37 ms | 2292 KB | Output is correct |
69 | Correct | 26 ms | 2292 KB | Output is correct |
70 | Correct | 30 ms | 2292 KB | Output is correct |
71 | Correct | 40 ms | 2292 KB | Output is correct |
72 | Correct | 37 ms | 2292 KB | Output is correct |
73 | Correct | 21 ms | 2292 KB | Output is correct |
74 | Correct | 20 ms | 2292 KB | Output is correct |
75 | Correct | 17 ms | 2292 KB | Output is correct |
76 | Correct | 18 ms | 2292 KB | Output is correct |
77 | Correct | 53 ms | 2292 KB | Output is correct |
78 | Correct | 3 ms | 2292 KB | Output is correct |
79 | Correct | 4 ms | 2292 KB | Output is correct |
80 | Correct | 6 ms | 2292 KB | Output is correct |
81 | Correct | 15 ms | 2292 KB | Output is correct |
82 | Correct | 30 ms | 2292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2040 KB | Output is correct |
2 | Correct | 5 ms | 2176 KB | Output is correct |
3 | Correct | 5 ms | 2176 KB | Output is correct |
4 | Correct | 3 ms | 2176 KB | Output is correct |
5 | Correct | 4 ms | 2176 KB | Output is correct |
6 | Correct | 4 ms | 2176 KB | Output is correct |
7 | Correct | 4 ms | 2176 KB | Output is correct |
8 | Correct | 5 ms | 2176 KB | Output is correct |
9 | Correct | 4 ms | 2176 KB | Output is correct |
10 | Correct | 4 ms | 2176 KB | Output is correct |
11 | Correct | 3 ms | 2228 KB | Output is correct |
12 | Correct | 3 ms | 2228 KB | Output is correct |
13 | Correct | 3 ms | 2228 KB | Output is correct |
14 | Correct | 3 ms | 2228 KB | Output is correct |
15 | Correct | 3 ms | 2228 KB | Output is correct |
16 | Correct | 4 ms | 2228 KB | Output is correct |
17 | Correct | 4 ms | 2228 KB | Output is correct |
18 | Correct | 4 ms | 2228 KB | Output is correct |
19 | Correct | 4 ms | 2228 KB | Output is correct |
20 | Correct | 3 ms | 2228 KB | Output is correct |
21 | Correct | 3 ms | 2228 KB | Output is correct |
22 | Correct | 4 ms | 2228 KB | Output is correct |
23 | Correct | 13 ms | 2288 KB | Output is correct |
24 | Correct | 4 ms | 2292 KB | Output is correct |
25 | Correct | 4 ms | 2292 KB | Output is correct |
26 | Correct | 5 ms | 2292 KB | Output is correct |
27 | Correct | 6 ms | 2292 KB | Output is correct |
28 | Correct | 7 ms | 2292 KB | Output is correct |
29 | Correct | 8 ms | 2292 KB | Output is correct |
30 | Correct | 3 ms | 2292 KB | Output is correct |
31 | Correct | 4 ms | 2292 KB | Output is correct |
32 | Correct | 3 ms | 2292 KB | Output is correct |
33 | Correct | 3 ms | 2292 KB | Output is correct |
34 | Correct | 3 ms | 2292 KB | Output is correct |
35 | Correct | 3 ms | 2292 KB | Output is correct |
36 | Correct | 9 ms | 2292 KB | Output is correct |
37 | Correct | 7 ms | 2292 KB | Output is correct |
38 | Correct | 12 ms | 2292 KB | Output is correct |
39 | Correct | 14 ms | 2292 KB | Output is correct |
40 | Correct | 5 ms | 2292 KB | Output is correct |
41 | Correct | 4 ms | 2292 KB | Output is correct |
42 | Correct | 7 ms | 2292 KB | Output is correct |
43 | Correct | 6 ms | 2292 KB | Output is correct |
44 | Correct | 3 ms | 2292 KB | Output is correct |
45 | Correct | 3 ms | 2292 KB | Output is correct |
46 | Correct | 7 ms | 2292 KB | Output is correct |
47 | Correct | 3 ms | 2292 KB | Output is correct |
48 | Correct | 5 ms | 2292 KB | Output is correct |
49 | Correct | 5 ms | 2292 KB | Output is correct |
50 | Correct | 6 ms | 2292 KB | Output is correct |
51 | Correct | 3 ms | 2292 KB | Output is correct |
52 | Correct | 5 ms | 2292 KB | Output is correct |
53 | Correct | 5 ms | 2292 KB | Output is correct |
54 | Correct | 6 ms | 2292 KB | Output is correct |
55 | Correct | 7 ms | 2292 KB | Output is correct |
56 | Correct | 3 ms | 2292 KB | Output is correct |
57 | Correct | 4 ms | 2292 KB | Output is correct |
58 | Correct | 5 ms | 2292 KB | Output is correct |
59 | Correct | 5 ms | 2292 KB | Output is correct |
60 | Correct | 3 ms | 2292 KB | Output is correct |
61 | Correct | 3 ms | 2292 KB | Output is correct |
62 | Correct | 4 ms | 2292 KB | Output is correct |
63 | Correct | 41 ms | 2292 KB | Output is correct |
64 | Correct | 7 ms | 2292 KB | Output is correct |
65 | Correct | 7 ms | 2292 KB | Output is correct |
66 | Correct | 40 ms | 2292 KB | Output is correct |
67 | Correct | 46 ms | 2292 KB | Output is correct |
68 | Correct | 37 ms | 2292 KB | Output is correct |
69 | Correct | 26 ms | 2292 KB | Output is correct |
70 | Correct | 30 ms | 2292 KB | Output is correct |
71 | Correct | 40 ms | 2292 KB | Output is correct |
72 | Correct | 37 ms | 2292 KB | Output is correct |
73 | Correct | 21 ms | 2292 KB | Output is correct |
74 | Correct | 20 ms | 2292 KB | Output is correct |
75 | Correct | 17 ms | 2292 KB | Output is correct |
76 | Correct | 18 ms | 2292 KB | Output is correct |
77 | Correct | 53 ms | 2292 KB | Output is correct |
78 | Correct | 3 ms | 2292 KB | Output is correct |
79 | Correct | 4 ms | 2292 KB | Output is correct |
80 | Correct | 6 ms | 2292 KB | Output is correct |
81 | Correct | 15 ms | 2292 KB | Output is correct |
82 | Correct | 30 ms | 2292 KB | Output is correct |
83 | Correct | 3 ms | 2292 KB | Output is correct |
84 | Correct | 82 ms | 2292 KB | Output is correct |
85 | Correct | 120 ms | 2292 KB | Output is correct |
86 | Correct | 47 ms | 2292 KB | Output is correct |
87 | Correct | 43 ms | 2292 KB | Output is correct |
88 | Correct | 127 ms | 2292 KB | Output is correct |
89 | Correct | 136 ms | 2292 KB | Output is correct |
90 | Correct | 25 ms | 2292 KB | Output is correct |
91 | Correct | 36 ms | 2292 KB | Output is correct |
92 | Correct | 8 ms | 2292 KB | Output is correct |
93 | Correct | 163 ms | 2292 KB | Output is correct |
94 | Correct | 19 ms | 2292 KB | Output is correct |
95 | Correct | 174 ms | 2292 KB | Output is correct |
96 | Correct | 174 ms | 2292 KB | Output is correct |
97 | Correct | 140 ms | 2292 KB | Output is correct |
98 | Correct | 21 ms | 2292 KB | Output is correct |
99 | Correct | 4 ms | 2292 KB | Output is correct |
100 | Correct | 28 ms | 2292 KB | Output is correct |
101 | Correct | 122 ms | 2292 KB | Output is correct |
102 | Correct | 165 ms | 2292 KB | Output is correct |
103 | Correct | 167 ms | 2292 KB | Output is correct |
104 | Correct | 30 ms | 2292 KB | Output is correct |
105 | Correct | 126 ms | 2292 KB | Output is correct |
106 | Correct | 67 ms | 2292 KB | Output is correct |
107 | Correct | 152 ms | 2292 KB | Output is correct |