Submission #27737

# Submission time Handle Problem Language Result Execution time Memory
27737 2017-07-13T14:48:54 Z 윤교준(#1174) 복불복 (OJUZ11_luck) C++11
100 / 100
79 ms 2284 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)im='-'==*p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define rb(x) ((x)&(-(x)))
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MOD (1000000007)
#define MAXN (105)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

ll C[MAXN][MAXN];
ll F[MAXN];

ll T[2][MAXN][MAXN];
int A[MAXN], B[MAXN];
int d[MAXN];
int N, K;
ll Ans;

void f(ll T[MAXN][MAXN], vector<int>& V) {
	for(int i = 0; i <= N; i++) fill(T[i], T[i]+N+2, 0);
	const int N = sz(V) - 1;
	//for(int v : V) printf("%d ", v); puts("");
	T[0][0] = 1;
	for(int i = 1; i <= N; i++) {
		for(int j = 0; j <= i; j++) {
			T[i][j] = ((j ? T[i-1][j-1] * (V[i]-j+1) % MOD : 0) + T[i-1][j]) % MOD;
		}
	}
}
ll g() {
	bool flag = false;
	for(int i = 1; i <= K; i++)
		if(d[i] < 1) { flag = true; break; }
	if(flag) return 0;
	{
		vector<int> V(1, 0);
		for(int i = K; i; i--) V.pb(d[i] - N + d[K+1]);
		f(T[1], V);
	}
	//printf("ANG %lld\n", T[1][2][2]);
	ll ret = 0;
	for(int c = max(0, K+d[K+1]-N); c <= K && c <= d[K+1]; c++) {
		//printf("SHIT c  %d\n", c);
		//printf("F[%d] * F[%d] * T[0][%d][%d] * T[1][%d][%d]\n", K-c, d[K+1]-c, N-K-1, N-K-d[K+1]+c, K, c);
		//printf("%lld %lld %lld %lld\n", F[K-c], F[d[K+1]-c], T[0][N-K-1][N-K-d[K+1]+c], T[1][K][c]);
		ret = (ret + F[K-c] * F[d[K+1]-c] % MOD * T[0][N-K-1][N-K-d[K+1]+c] % MOD * T[1][K][c]) % MOD;
		//printf("RET %lld\n", ret);
	}
	return ret;
}
int main() {
	F[0] = 1; for(int i = 1; i < MAXN; i++) F[i] = F[i-1] * i % MOD;
	for(int i = 0; i < MAXN; i++) for(int j = 0; j <= i; j++) {
		if(!j || i == j) C[i][j] = 1;
		else C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
	}
	scanf("%d%d", &N, &K); if(N == K) { printf("%lld\n", F[N]); return 0; }
	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); sort(B+1, B+N+1); reverse(A+1, A+N+1); reverse(B+1, B+N+1);
	//for(int X = 0; X <= 12; X++) {
	for(int X = 0; X <= 2002; X++) {
		//printf("TEST X = %d\n", X);
		for(int i = K+1, j = N; i <= N; i++) {
			for(; j && A[i] + B[j] <= X; j--);
			d[i] = j+1;
		}
		//for(int i = K+1; i <= N; i++) printf("%d : %d\n", i, d[i]);
		bool flag = false;
		for(int i = K+1; i <= N; i++)
			if(N < d[i]) { flag = true; break; }
		if(flag) continue;
		for(int i = K+1; i <= N; i++) d[i] = N - d[i] + 1;
		{
			vector<int> V(1, 0);
			for(int i = K+2; i <= N; i++) V.pb(d[i] - d[K+1]);
			f(T[0], V);
		}
		{
			// Yes Equal
			for(int i = K, j = 1; i; i--) {
				for(; j <= N && A[i] + B[j] >= X; j++);
				d[i] = j-1;
			}
			Ans = (Ans + g()) % MOD;
		}
		{
			// No Equal
			for(int i = K, j = 1; i; i--) {
				for(; j <= N && A[i] + B[j] > X; j++);
				d[i] = j-1;
			}
			Ans = (Ans - g() + MOD) % MOD;
		}
	}
	printf("%lld\n", Ans);
	return 0;
}

Compilation message

luck.cpp: In function 'int main()':
luck.cpp:72:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K); if(N == K) { printf("%lld\n", F[N]); return 0; }
                       ^
luck.cpp:73:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
                                                ^
luck.cpp:74:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d", &B[i]);
                                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2284 KB Output is correct
2 Correct 0 ms 2284 KB Output is correct
3 Correct 0 ms 2284 KB Output is correct
4 Correct 0 ms 2284 KB Output is correct
5 Correct 0 ms 2284 KB Output is correct
6 Correct 0 ms 2284 KB Output is correct
7 Correct 0 ms 2284 KB Output is correct
8 Correct 0 ms 2284 KB Output is correct
9 Correct 0 ms 2284 KB Output is correct
10 Correct 0 ms 2284 KB Output is correct
11 Correct 0 ms 2284 KB Output is correct
12 Correct 0 ms 2284 KB Output is correct
13 Correct 0 ms 2284 KB Output is correct
14 Correct 0 ms 2284 KB Output is correct
15 Correct 0 ms 2284 KB Output is correct
16 Correct 0 ms 2284 KB Output is correct
17 Correct 0 ms 2284 KB Output is correct
18 Correct 0 ms 2284 KB Output is correct
19 Correct 0 ms 2284 KB Output is correct
20 Correct 0 ms 2284 KB Output is correct
21 Correct 0 ms 2284 KB Output is correct
22 Correct 0 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2284 KB Output is correct
2 Correct 39 ms 2284 KB Output is correct
3 Correct 19 ms 2284 KB Output is correct
4 Correct 19 ms 2284 KB Output is correct
5 Correct 29 ms 2284 KB Output is correct
6 Correct 16 ms 2284 KB Output is correct
7 Correct 53 ms 2284 KB Output is correct
8 Correct 3 ms 2284 KB Output is correct
9 Correct 3 ms 2284 KB Output is correct
10 Correct 0 ms 2284 KB Output is correct
11 Correct 0 ms 2284 KB Output is correct
12 Correct 0 ms 2284 KB Output is correct
13 Correct 0 ms 2284 KB Output is correct
14 Correct 36 ms 2284 KB Output is correct
15 Correct 9 ms 2284 KB Output is correct
16 Correct 69 ms 2284 KB Output is correct
17 Correct 59 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2284 KB Output is correct
2 Correct 0 ms 2284 KB Output is correct
3 Correct 0 ms 2284 KB Output is correct
4 Correct 0 ms 2284 KB Output is correct
5 Correct 0 ms 2284 KB Output is correct
6 Correct 0 ms 2284 KB Output is correct
7 Correct 0 ms 2284 KB Output is correct
8 Correct 0 ms 2284 KB Output is correct
9 Correct 0 ms 2284 KB Output is correct
10 Correct 0 ms 2284 KB Output is correct
11 Correct 0 ms 2284 KB Output is correct
12 Correct 0 ms 2284 KB Output is correct
13 Correct 0 ms 2284 KB Output is correct
14 Correct 0 ms 2284 KB Output is correct
15 Correct 0 ms 2284 KB Output is correct
16 Correct 0 ms 2284 KB Output is correct
17 Correct 0 ms 2284 KB Output is correct
18 Correct 0 ms 2284 KB Output is correct
19 Correct 0 ms 2284 KB Output is correct
20 Correct 0 ms 2284 KB Output is correct
21 Correct 0 ms 2284 KB Output is correct
22 Correct 0 ms 2284 KB Output is correct
23 Correct 0 ms 2284 KB Output is correct
24 Correct 0 ms 2284 KB Output is correct
25 Correct 0 ms 2284 KB Output is correct
26 Correct 3 ms 2284 KB Output is correct
27 Correct 0 ms 2284 KB Output is correct
28 Correct 0 ms 2284 KB Output is correct
29 Correct 0 ms 2284 KB Output is correct
30 Correct 0 ms 2284 KB Output is correct
31 Correct 3 ms 2284 KB Output is correct
32 Correct 0 ms 2284 KB Output is correct
33 Correct 0 ms 2284 KB Output is correct
34 Correct 0 ms 2284 KB Output is correct
35 Correct 3 ms 2284 KB Output is correct
36 Correct 0 ms 2284 KB Output is correct
37 Correct 0 ms 2284 KB Output is correct
38 Correct 3 ms 2284 KB Output is correct
39 Correct 0 ms 2284 KB Output is correct
40 Correct 0 ms 2284 KB Output is correct
41 Correct 0 ms 2284 KB Output is correct
42 Correct 0 ms 2284 KB Output is correct
43 Correct 0 ms 2284 KB Output is correct
44 Correct 3 ms 2284 KB Output is correct
45 Correct 3 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2284 KB Output is correct
2 Correct 0 ms 2284 KB Output is correct
3 Correct 0 ms 2284 KB Output is correct
4 Correct 0 ms 2284 KB Output is correct
5 Correct 0 ms 2284 KB Output is correct
6 Correct 0 ms 2284 KB Output is correct
7 Correct 0 ms 2284 KB Output is correct
8 Correct 0 ms 2284 KB Output is correct
9 Correct 0 ms 2284 KB Output is correct
10 Correct 0 ms 2284 KB Output is correct
11 Correct 0 ms 2284 KB Output is correct
12 Correct 0 ms 2284 KB Output is correct
13 Correct 0 ms 2284 KB Output is correct
14 Correct 0 ms 2284 KB Output is correct
15 Correct 0 ms 2284 KB Output is correct
16 Correct 0 ms 2284 KB Output is correct
17 Correct 0 ms 2284 KB Output is correct
18 Correct 0 ms 2284 KB Output is correct
19 Correct 0 ms 2284 KB Output is correct
20 Correct 0 ms 2284 KB Output is correct
21 Correct 0 ms 2284 KB Output is correct
22 Correct 0 ms 2284 KB Output is correct
23 Correct 49 ms 2284 KB Output is correct
24 Correct 39 ms 2284 KB Output is correct
25 Correct 19 ms 2284 KB Output is correct
26 Correct 19 ms 2284 KB Output is correct
27 Correct 29 ms 2284 KB Output is correct
28 Correct 16 ms 2284 KB Output is correct
29 Correct 53 ms 2284 KB Output is correct
30 Correct 3 ms 2284 KB Output is correct
31 Correct 3 ms 2284 KB Output is correct
32 Correct 0 ms 2284 KB Output is correct
33 Correct 0 ms 2284 KB Output is correct
34 Correct 0 ms 2284 KB Output is correct
35 Correct 0 ms 2284 KB Output is correct
36 Correct 36 ms 2284 KB Output is correct
37 Correct 9 ms 2284 KB Output is correct
38 Correct 69 ms 2284 KB Output is correct
39 Correct 59 ms 2284 KB Output is correct
40 Correct 49 ms 2284 KB Output is correct
41 Correct 36 ms 2284 KB Output is correct
42 Correct 19 ms 2284 KB Output is correct
43 Correct 43 ms 2284 KB Output is correct
44 Correct 53 ms 2284 KB Output is correct
45 Correct 36 ms 2284 KB Output is correct
46 Correct 46 ms 2284 KB Output is correct
47 Correct 46 ms 2284 KB Output is correct
48 Correct 43 ms 2284 KB Output is correct
49 Correct 53 ms 2284 KB Output is correct
50 Correct 49 ms 2284 KB Output is correct
51 Correct 46 ms 2284 KB Output is correct
52 Correct 63 ms 2284 KB Output is correct
53 Correct 56 ms 2284 KB Output is correct
54 Correct 49 ms 2284 KB Output is correct
55 Correct 9 ms 2284 KB Output is correct
56 Correct 6 ms 2284 KB Output is correct
57 Correct 9 ms 2284 KB Output is correct
58 Correct 23 ms 2284 KB Output is correct
59 Correct 53 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2284 KB Output is correct
2 Correct 0 ms 2284 KB Output is correct
3 Correct 0 ms 2284 KB Output is correct
4 Correct 0 ms 2284 KB Output is correct
5 Correct 0 ms 2284 KB Output is correct
6 Correct 0 ms 2284 KB Output is correct
7 Correct 0 ms 2284 KB Output is correct
8 Correct 0 ms 2284 KB Output is correct
9 Correct 0 ms 2284 KB Output is correct
10 Correct 0 ms 2284 KB Output is correct
11 Correct 0 ms 2284 KB Output is correct
12 Correct 0 ms 2284 KB Output is correct
13 Correct 0 ms 2284 KB Output is correct
14 Correct 0 ms 2284 KB Output is correct
15 Correct 0 ms 2284 KB Output is correct
16 Correct 0 ms 2284 KB Output is correct
17 Correct 0 ms 2284 KB Output is correct
18 Correct 0 ms 2284 KB Output is correct
19 Correct 0 ms 2284 KB Output is correct
20 Correct 0 ms 2284 KB Output is correct
21 Correct 0 ms 2284 KB Output is correct
22 Correct 0 ms 2284 KB Output is correct
23 Correct 49 ms 2284 KB Output is correct
24 Correct 39 ms 2284 KB Output is correct
25 Correct 19 ms 2284 KB Output is correct
26 Correct 19 ms 2284 KB Output is correct
27 Correct 29 ms 2284 KB Output is correct
28 Correct 16 ms 2284 KB Output is correct
29 Correct 53 ms 2284 KB Output is correct
30 Correct 3 ms 2284 KB Output is correct
31 Correct 3 ms 2284 KB Output is correct
32 Correct 0 ms 2284 KB Output is correct
33 Correct 0 ms 2284 KB Output is correct
34 Correct 0 ms 2284 KB Output is correct
35 Correct 0 ms 2284 KB Output is correct
36 Correct 36 ms 2284 KB Output is correct
37 Correct 9 ms 2284 KB Output is correct
38 Correct 69 ms 2284 KB Output is correct
39 Correct 59 ms 2284 KB Output is correct
40 Correct 0 ms 2284 KB Output is correct
41 Correct 0 ms 2284 KB Output is correct
42 Correct 0 ms 2284 KB Output is correct
43 Correct 3 ms 2284 KB Output is correct
44 Correct 0 ms 2284 KB Output is correct
45 Correct 0 ms 2284 KB Output is correct
46 Correct 0 ms 2284 KB Output is correct
47 Correct 0 ms 2284 KB Output is correct
48 Correct 3 ms 2284 KB Output is correct
49 Correct 0 ms 2284 KB Output is correct
50 Correct 0 ms 2284 KB Output is correct
51 Correct 0 ms 2284 KB Output is correct
52 Correct 3 ms 2284 KB Output is correct
53 Correct 0 ms 2284 KB Output is correct
54 Correct 0 ms 2284 KB Output is correct
55 Correct 3 ms 2284 KB Output is correct
56 Correct 0 ms 2284 KB Output is correct
57 Correct 0 ms 2284 KB Output is correct
58 Correct 0 ms 2284 KB Output is correct
59 Correct 0 ms 2284 KB Output is correct
60 Correct 0 ms 2284 KB Output is correct
61 Correct 3 ms 2284 KB Output is correct
62 Correct 3 ms 2284 KB Output is correct
63 Correct 49 ms 2284 KB Output is correct
64 Correct 36 ms 2284 KB Output is correct
65 Correct 19 ms 2284 KB Output is correct
66 Correct 43 ms 2284 KB Output is correct
67 Correct 53 ms 2284 KB Output is correct
68 Correct 36 ms 2284 KB Output is correct
69 Correct 46 ms 2284 KB Output is correct
70 Correct 46 ms 2284 KB Output is correct
71 Correct 43 ms 2284 KB Output is correct
72 Correct 53 ms 2284 KB Output is correct
73 Correct 49 ms 2284 KB Output is correct
74 Correct 46 ms 2284 KB Output is correct
75 Correct 63 ms 2284 KB Output is correct
76 Correct 56 ms 2284 KB Output is correct
77 Correct 49 ms 2284 KB Output is correct
78 Correct 9 ms 2284 KB Output is correct
79 Correct 6 ms 2284 KB Output is correct
80 Correct 9 ms 2284 KB Output is correct
81 Correct 23 ms 2284 KB Output is correct
82 Correct 53 ms 2284 KB Output is correct
83 Correct 0 ms 2284 KB Output is correct
84 Correct 53 ms 2284 KB Output is correct
85 Correct 59 ms 2284 KB Output is correct
86 Correct 19 ms 2284 KB Output is correct
87 Correct 19 ms 2284 KB Output is correct
88 Correct 79 ms 2284 KB Output is correct
89 Correct 63 ms 2284 KB Output is correct
90 Correct 26 ms 2284 KB Output is correct
91 Correct 26 ms 2284 KB Output is correct
92 Correct 0 ms 2284 KB Output is correct
93 Correct 49 ms 2284 KB Output is correct
94 Correct 6 ms 2284 KB Output is correct
95 Correct 53 ms 2284 KB Output is correct
96 Correct 46 ms 2284 KB Output is correct
97 Correct 39 ms 2284 KB Output is correct
98 Correct 16 ms 2284 KB Output is correct
99 Correct 0 ms 2284 KB Output is correct
100 Correct 9 ms 2284 KB Output is correct
101 Correct 49 ms 2284 KB Output is correct
102 Correct 59 ms 2284 KB Output is correct
103 Correct 46 ms 2284 KB Output is correct
104 Correct 13 ms 2284 KB Output is correct
105 Correct 49 ms 2284 KB Output is correct
106 Correct 23 ms 2284 KB Output is correct
107 Correct 43 ms 2284 KB Output is correct